Skip to content

Commit 0547172

Browse files
Checks: Fixed: Crash in CPP_L037 Incompatible Pointers on array arguments stinb/crashlogs#789 [autosync]
1 parent 16ddc15 commit 0547172

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

  • CodeCheck/All Checks/Language Specific/C and C++/Libraries/CPP_L037
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Reproducer for crash #789
2+
#include <string.h>
3+
#include <stdint.h>
4+
5+
struct S {
6+
uint8_t buf[16];
7+
uint16_t ibuf[8];
8+
};
9+
10+
/* A: ordinary memcpy with local-array lvalues */
11+
void f_local(void) {
12+
char a[16];
13+
char b[16];
14+
memcpy(a, b, 16); // UndCC_Valid
15+
memcmp(a, b, 16); // UndCC_Valid
16+
memmove(a, b, 16); // UndCC_Valid
17+
}
18+
19+
/* B: ordinary memcpy on struct member arrays */
20+
void f_member(struct S *s) {
21+
memcpy(s->buf, s->buf, 16); // UndCC_Valid
22+
memcmp(s->buf, s->ibuf, 16); // UndCC_Violation
23+
}
24+
25+
/* C: FORTIFY builtin with local-array lvalues */
26+
void f_fortify(void) {
27+
char a[16];
28+
char b[16];
29+
__builtin___memcpy_chk(a, b, 16, __builtin_object_size(a, 0)); // UndCC_Valid
30+
__builtin___memmove_chk(a, b, 16, __builtin_object_size(a, 0)); // UndCC_Valid
31+
}

0 commit comments

Comments
 (0)