Getting undeclared error for the variable which is already declared.
I have this piece of code to compile with insure++
static int ABC
(
unsigned char *buffer,
int buffer_size,
int num,
)
{
memset(buffer, '\0', buffer_size); void* xyz = # memcpy(buffer, xyz, "ABCD");
''''
but after cmpilation, i get this error:
" error: 'xyz' undeclared (first use in this function)"
but it is already declared.
Comments
-
This code is not valid. memcpy takes three arguments:
void *memcpy(void *dest, void *src, size_t count);You have a string literal for the third argument, instead of the count of number of bytes to copy.
Also, what platform and compiler are you using?
1 -
Yeah, i was wrong it is
memcpy(buffer, xyz, 5);
I am in Linux and using gcc version 4.8.50 -
the question is xyz is declared but i am getting undeclared error for it in line memecpy.
0 -
I cannot reproduce this behavior with the information that you've given me so far.
Please contact our technical support department, (support@parasoft.com). Please include a small, compile-able test-case which reproduces this behavior.This is my test-case:
#include <string.h>
static void ABC (unsigned char *buffer, int buffer_size, int num)
{
memset(buffer, '\0', buffer_size);
void *xyz = #
memcpy(buffer, xyz, 5);
}This compiles just fine with insure.
1 -
I compiled your test case and I got this error:
error: 'xyz' undeclared (first use in this function)
void *xyz = #0 -
Hi @shajabedi ,
I could confirm, the test case that @Rich provided compiled just fine with Insure++. I suspect someting wrong with either your setup or environment.
As @Rich wrote, please, create reproducible test case that compiles with your compiler and reproduces the error, and contact our technical support.0 -
The error you are encountering is due to the placement of the variable declaration
void* xyz = #.It seems you have declared xyz inside the memset function block, making it out of scope for the memcpy function.
To resolve this, move the
void* xyz = #
declaration to the beginning of the ABC function, before the memset and memcpy calls. This way, XYZ will be in scope for both functions, and the compilation error should be resolved. I have encountered a similar issue while working as a programmer for an industry-leading ai services provider0