Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
None
-
None
-
None
-
$ uname -sr && aCC -V
HP-UX B.11.31
aCC: HP C/aC++ B3910B A.06.16 [Nov 26 2007]
-
Compiler Warning
Description
Copying data from one buffer to a smaller one results in the warning, even if you check for overflow before the copy.
$ cat t.cpp && aCC +w -c t.cpp #include <string.h> int main (int argc, char* argv[]) { char a [32] = { 'a', 'b', 'c', '\0' }; char b [16]; const size_t n = strlen (a) + 1; if (sizeof (b) < n) return 1; strcpy (b, a); return 0; } "t.cpp", line 12, procedure main: warning #20206-D: Out of bound access (In expression "strcpy((char*)b, (char*)a)", variable "b" [t.cpp:6] (type: char [16]) has byte range [0 .. 15], writing byte range [0 .. 31].)
A workaround is to create a plain pointer to the source buffer and then do the copy.
Attachments
Issue Links
- is depended upon by
-
STDCXX-755 [HP aCC 6.16] Potential null pointer dereference in locale.cpp
- Closed