10 for (i
= 0; i
< 50; i
++)
24 char a
[] = "abcdefghijklmnopqrstuvwxyz";
27 /* testing memcpy/strcpy overlap */
29 for (i
= 0; i
< 50; i
++) {
30 x
[i
] = i
+1; // don't put any zeroes in there
32 for (i
= 50; i
< 100; i
++) {
33 // because of the errors, the strcpy's will overrun, so put some
34 // zeroes in the second half to stop them eventually
39 memcpy(x
+20, x
, 20); // ok
40 memcpy(x
+20, x
, 21); // overlap
41 memcpy(x
, x
+20, 20); // ok
42 memcpy(x
, x
+20, 21); // overlap
44 strncpy(x
+20, x
, 20); // ok
45 strncpy(x
+20, x
, 21); // overlap
46 strncpy(x
, x
+20, 20); // ok
47 strncpy(x
, x
+20, 21); // overlap
50 strcpy(x
, x
+20); // ok
54 strcpy(x
, x
+20); // overlap
57 strcpy(x
+20, x
); // ok
62 strcpy(x+20, x); // overlap, but runs forever (or until it seg faults)
65 /* testing strcpy, strncpy() */
87 /* testing strncat() */
108 /* Nb: can't actually get strcat warning -- if any overlap occurs, it will
109 always run forever, I think... */
111 for ( i
= 0; i
< 2; i
++)
112 strncat(a
+20, a
, 21); // run twice to check 2nd error isn't shown
113 strncat(a
, a
+20, 21);
115 /* This is ok, but once gave a warning when strncpy() was wrong,
116 and used 'n' for the length, even when the src was shorter than 'n' */
120 strcpy( src
, "short" );
121 strncpy( dest
, src
, 20 );