summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorjvoisin2023-06-22 18:07:41 +0200
committerjvoisin2023-06-22 18:07:41 +0200
commit532f4bfd0ba906e5a1410b9d2a46cf8a4992f062 (patch)
tree6d84f1e0f285c9aff10389904b4e5ad9e6b5c2ea /include
parentaf7480d0190cb5dcf279a7ddfab320ff084a3471 (diff)
Add tests for stcncpy
Diffstat (limited to 'include')
-rw-r--r--include/string.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/include/string.h b/include/string.h
index f738901..9bf17a0 100644
--- a/include/string.h
+++ b/include/string.h
@@ -104,8 +104,13 @@ __access(write_only, 1)
104__access(read_only, 2, 3) 104__access(read_only, 2, 3)
105_FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n) 105_FORTIFY_FN(stpncpy) char *stpncpy(char *__d, const char *__s, size_t __n)
106{ 106{
107 size_t __b = __bos(__d, 0); 107 /* trap if pointers are overlapping but not if dst == src.
108 * gcc seems to like to generate code that relies on dst == src */
109 if ((__d < __s && __d + __n > __s) ||
110 (__s < __d && __s + __n > __d))
111 __builtin_trap();
108 112
113 size_t __b = __bos(__d, 0);
109 if (__n > __b && strlen(__s) + 1 > __b) 114 if (__n > __b && strlen(__s) + 1 > __b)
110 __builtin_trap(); 115 __builtin_trap();
111 return __orig_stpncpy(__d, __s, __n); 116 return __orig_stpncpy(__d, __s, __n);