Board index » cppbuilder » CodeGuard error not understood
Derek Harvey
![]() CBuilder Developer |
CodeGuard error not understood2008-03-25 09:23:22 PM cppbuilder11 Hi Folks, I am getting a CodeGuard error report in a place where I cannot see any error in my code and where it works. Extract from function body: static char item[100]; char tmp[20]; memset( item, ' ', 98 ); item[98] = '\0'; // setting spaces and terminator memcpy( item + <const == 12>, <function returning Char*, len 10>, 10 ); // CG error here sprintf( tmp, "%10.2f", <float value>); memcpy( item + <const == 30>, tmp, strlen(tmp) ); CG error here as well The offset constants are defined by #defines elsewhere as an easy way of controlling the layout of item built up from a number of things. (I know there are 'more modern?' ways of doing this but as 'it wasn't broke I didn't intend to fix it'!) CG says I am trying to access 100 bytes from 'item + ...' when item is only 100 bytes, BUT I am only trying to access 10 bytes!? The result if I press on from the errors is correct. The above code, and many similar examples, has been in use for several versions of BCB and CG did not report any errors in BCB6. Is there something wrong with this code that was not wrong before? Or is this a bug in CodeGuard, in not understanding memcpy function?? The CG errors do not occur if I remove the 'static' or define item as, e.g., 300 bytes. Derek |