summaryrefslogtreecommitdiff
path: root/string
diff options
context:
space:
mode:
Diffstat (limited to 'string')
-rw-r--r--string/Makefile3
-rw-r--r--string/bits/string2.h7
-rw-r--r--string/bug-strncat1.c30
-rw-r--r--string/bug-strpbrk1.c18
-rw-r--r--string/bug-strspn1.c18
5 files changed, 72 insertions, 4 deletions
diff --git a/string/Makefile b/string/Makefile
index e133b53266..970147c4a8 100644
--- a/string/Makefile
+++ b/string/Makefile
@@ -46,7 +46,8 @@ routines := strcat strchr strcmp strcoll strcpy strcspn \
o-objects.ob := memcpy.o memset.o memchr.o
tests := tester inl-tester noinl-tester testcopy test-ffs \
- tst-strlen stratcliff tst-svc tst-inlcall
+ tst-strlen stratcliff tst-svc tst-inlcall \
+ bug-strncat1 bug-strspn1 bug-strpbrk1
distribute := memcopy.h pagecopy.h tst-svc.expect
diff --git a/string/bits/string2.h b/string/bits/string2.h
index de427f8cb4..bf174a4c8c 100644
--- a/string/bits/string2.h
+++ b/string/bits/string2.h
@@ -727,7 +727,8 @@ __stpcpy_small (char *__dest,
__builtin_constant_p (src) && __builtin_constant_p (n) \
? (strlen (src) < ((size_t) (n)) \
? strcat (__dest, src) \
- : (memcpy (strchr (__dest, '\0'), src, n), __dest)) \
+ : (*((char *) __mempcpy (strchr (__dest, '\0'), \
+ src, n)) = '\0', __dest)) \
: strncat (dest, src, n); }))
# else
# define strncat(dest, src, n) \
@@ -914,7 +915,7 @@ __strcspn_c3 (__const char *__s, char __reject1, char __reject2,
({ char __a0, __a1, __a2; \
(__builtin_constant_p (accept) && __string2_1bptr_p (accept) \
? ((__a0 = ((__const char *) (accept))[0], __a0 == '\0') \
- ? 0 \
+ ? ((void) (s), 0) \
: ((__a1 = ((__const char *) (accept))[1], __a1 == '\0') \
? __strspn_c1 (s, __a0) \
: ((__a2 = ((__const char *) (accept))[2], __a2 == '\0') \
@@ -969,7 +970,7 @@ __strspn_c3 (__const char *__s, char __accept1, char __accept2, char __accept3)
({ char __a0, __a1, __a2; \
(__builtin_constant_p (accept) && __string2_1bptr_p (accept) \
? ((__a0 = ((__const char *) (accept))[0], __a0 == '\0') \
- ? NULL \
+ ? ((void) (s), NULL) \
: ((__a1 = ((__const char *) (accept))[1], __a1 == '\0') \
? strchr (s, __a0) \
: ((__a2 = ((__const char *) (accept))[2], __a2 == '\0') \
diff --git a/string/bug-strncat1.c b/string/bug-strncat1.c
new file mode 100644
index 0000000000..0e41a3e727
--- /dev/null
+++ b/string/bug-strncat1.c
@@ -0,0 +1,30 @@
+/* Test case by Joseph S. Myers <jsm28@cam.ac.uk>. */
+#define __USE_STRING_INLINES
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+char d[3] = "\0\1\2";
+
+int
+main (void)
+{
+ strncat (d, "\5\6", 1);
+ if (d[0] != '\5')
+ {
+ puts ("d[0] != '\\5'");
+ exit (1);
+ }
+ if (d[1] != '\0')
+ {
+ puts ("d[1] != '\\0'");
+ exit (1);
+ }
+ if (d[2] != '\2')
+ {
+ puts ("d[2] != '\\3'");
+ exit (1);
+ }
+
+ exit (0);
+}
diff --git a/string/bug-strpbrk1.c b/string/bug-strpbrk1.c
new file mode 100644
index 0000000000..7d5eef8e41
--- /dev/null
+++ b/string/bug-strpbrk1.c
@@ -0,0 +1,18 @@
+/* Test case by Joseph S. Myers <jsm28@cam.ac.uk>. */
+#define __USE_STRING_INLINES
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int
+main (void)
+{
+ const char *a = "abc";
+ const char *b = a;
+
+ strpbrk (b++, "");
+ if (b != a + 1)
+ exit (1);
+
+ exit (0);
+}
diff --git a/string/bug-strspn1.c b/string/bug-strspn1.c
new file mode 100644
index 0000000000..cd6c012275
--- /dev/null
+++ b/string/bug-strspn1.c
@@ -0,0 +1,18 @@
+/* Test case by Joseph S. Myers <jsm28@cam.ac.uk>. */
+#define __USE_STRING_INLINES
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+int
+main (void)
+{
+ const char *a = "abc";
+ const char *b = a;
+
+ strspn (b++, "");
+ if (b != a + 1)
+ exit (1);
+
+ exit (0);
+}