diff options
Diffstat (limited to 'string')
-rw-r--r-- | string/bits/string2.h | 8 | ||||
-rw-r--r-- | string/tester.c | 27 |
2 files changed, 32 insertions, 3 deletions
diff --git a/string/bits/string2.h b/string/bits/string2.h index 4d1baa2062..336aafef9a 100644 --- a/string/bits/string2.h +++ b/string/bits/string2.h @@ -118,7 +118,7 @@ __STRING2_COPY_TYPE (8); __uint8_t __c = (__uint8_t) (c); \ \ /* This `switch' statement will be removed at compile-time. */ \ - switch ((unsigned int) n) \ + switch ((unsigned int) (n)) \ { \ case 15: \ __u->__ui = __c * 0x01010101; \ @@ -1078,8 +1078,10 @@ __strtok_r_1c (char *__s, char __sep, char **__nextp) __extension__ \ ({ char __r0, __r1, __r2; \ (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \ - && (__r0 = ((__const char *) (reject))[0], __r0 != '\0') \ - ? ((__r1 = ((__const char *) (reject))[1], __r1 == '\0') \ + && (__r0 = ((__const char *) (reject))[0], \ + ((__const char *) (reject))[0] != '\0') \ + ? ((__r1 = ((__const char *) (reject))[1], \ + ((__const char *) (reject))[1] == '\0') \ ? __strsep_1c (s, __r0) \ : ((__r2 = ((__const char *) (reject))[2], __r2 == '\0') \ ? __strsep_2c (s, __r0, __r1) \ diff --git a/string/tester.c b/string/tester.c index 4fed10e4b4..d9043e046f 100644 --- a/string/tester.c +++ b/string/tester.c @@ -807,6 +807,7 @@ test_strtok_r (void) void test_strsep (void) { + char *ptr; it = "strsep"; cp = strcpy(one, "first, second, third"); equal(strsep(&cp, ", "), "first", 1); /* Basic test. */ @@ -901,6 +902,32 @@ test_strsep (void) equal(strsep(&cp, "xy,"), "", 71); check(strsep(&cp, "x,y") == NULL, 72); check(strsep(&cp, ",xy") == NULL, 73); /* Persistence. */ + + cp = strcpy(one, "ABC"); + one[4] = ':'; + equal(strsep(&cp, "C"), "AB", 74); /* Access beyond NUL. */ + ptr = strsep(&cp, ":"); + equal(ptr, "", 75); + check(ptr == one + 3, 76); + check(cp == NULL, 77); + + cp = strcpy(one, "ABC"); + one[4] = ':'; + equal(strsep(&cp, "CD"), "AB", 78); /* Access beyond NUL. */ + ptr = strsep(&cp, ":."); + equal(ptr, "", 79); + check(ptr == one + 3, 80); + + cp = strcpy(one, "ABC"); /* No token in string. */ + equal(strsep(&cp, ","), "ABC", 81); + check(cp == NULL, 82); + + *one = '\0'; /* Empty string. */ + cp = one; + ptr = strsep(&cp, ","); + equal(ptr, "", 83); + check(ptr == one, 84); + check(cp == NULL, 85); } void |