mirror of
https://github.com/Zenithsiz/ftmemsim-valgrind.git
synced 2026-02-04 10:21:20 +00:00
34 lines
743 B
C
34 lines
743 B
C
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
// glibc's versions of functions like strlen() do things word-wise instead
|
|
// of byte-wise, which means they can overrun the end of strings, etc.
|
|
// Naughty, but must be safe, I guess; Annelid copes with this in the same
|
|
// way Memcheck does, letting it happen unless the --partial-loads-ok=no
|
|
// option is used.
|
|
|
|
int main(void)
|
|
{
|
|
char* h = "hello, world";
|
|
char* p = strdup(h);
|
|
char u[20];
|
|
char* c;
|
|
int len;
|
|
|
|
len = strlen(p);
|
|
|
|
c = strchr (p, 'l');
|
|
c = strchr (p, 'x');
|
|
|
|
c = strrchr(p, 'l');
|
|
c = strrchr(p, 'x');
|
|
|
|
c = memchr (p, 'l', len); // glibc version ok?
|
|
c = memchr (p, 'x', len);
|
|
|
|
memcpy(u, p, len+1); // glibc version ok?
|
|
|
|
return 0;
|
|
}
|