1 2 #include <stdlib.h> 3 #include <string.h> 4 5 // glibc's versions of functions like strlen() do things word-wise instead 6 // of byte-wise, which means they can overrun the end of strings, etc. 7 // Naughty, but must be safe, I guess; Annelid copes with this in the same 8 // way Memcheck does, letting it happen unless the --partial-loads-ok=no 9 // option is used. 10 11 int main(void) 12 { 13 char* h = "hello, world"; 14 char* p = strdup(h); 15 char u[20]; 16 char* c; 17 int len; 18 19 len = strlen(p); 20 21 c = strchr (p, 'l'); 22 c = strchr (p, 'x'); 23 24 c = strrchr(p, 'l'); 25 c = strrchr(p, 'x'); 26 27 c = memchr (p, 'l', len); // glibc version ok? 28 c = memchr (p, 'x', len); 29 30 memcpy(u, p, len+1); // glibc version ok? 31 32 return 0; 33 } 34