Error Handling: Invalid arguments & #39; Candidates are: void * memcpy (void *, const void *,?)

Source: Internet
Author: User

Error Handling: Invalid arguments 'candidates are: void * memcpy (void *, const void *,?)




Problems encountered during JNI development.

Symptoms:

Invalid arguments ' Candidates are: void * memcpy(void *, const void *, ?)Invalid arguments 'Candidates are: void * malloc(?)

You can also see the function prototype in the contained header file, as shown below:

extern __mallocfunc void*  malloc(size_t);extern void*  memcpy(void *, const void *, size_t);

In the error message: Invalid arguments, which means the parameter is Invalid. It is obvious that the size_t parameter is not properly identified.


Because of this analysis, this problem occurs in all methods that use size_t parameters, such as memset, memccpy, memchr, and memcmp.


There are two ways to solve this problem. First, use other methods instead of memcpy, malloc, and memset. Second: enable the system to normally identify the size_t type, which is a fundamental solution to this problem. The following provides detailed solutions for each of the two ideas.


1. Alternative Method


You can use new and strcpy to replace malloc and memcpy. Here, the malloc and memcpy methods are used. You can find corresponding methods to replace other methods.

For example:

Originally:

 Const char* Tmp = env-> GetStringUTFChars (jstr_mac, NULL );
 Size_tLen = strlen (tmp) + 1;

 Char* Mac = (Char*) Malloc (len );
 Memcpy (mac, tmp, len );

 

You can change it:

 Const char* Tmp = env-> GetStringUTFChars (jstr_mac, NULL );
 IntLen = strlen (tmp) + 1;
 Char* Mac =New Char[Len];
 Strcpy (mac, tmp );


Second: enable the system to recognize the size_t type

The solution is as follows:

  1. Right-click the Project properties> C/C ++ General> Paths and Symbols.

  2. Select the "des" label

F: \ android-ndk-r9b \ platforms \ android-19 \ arch-arm \ usr \ include

F: \ android-ndk-r9b \ toolchains \ arm-linux-androideabi-4.8 \ prebuilt \ windows \ lib \ gcc \ arm-linux-androideabi \ 4.8 \ include

This problem can be solved.


Note:

You can also add the following two header file libraries to the project's include:

F: \ android-ndk-r9b \ sources \ cxx-stl \ gnu-libstdc ++ \ 4.8 \ include

F: \ android-ndk-r9b \ sources \ cxx-stl \ gnu-libstdc ++ \ 4.8 \ libs \ armeabi-v7a \ include


----------------------------------

Welcome to browse, technical exchange, respect for labor achievements, repost, please indicate the source, thank you!

Http://blog.csdn.net/netwalk/article/details/22295585



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.