summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
Diffstat (limited to 'string.c')
-rw-r--r--string.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/string.c b/string.c
index 5bbb1b3..e50716a 100644
--- a/string.c
+++ b/string.c
@@ -1,4 +1,40 @@
-#include <string.h> /* strndup */
+#include <assert.h> /* assert */
+#include <string.h> /* memcpy, strcpy, strncat, strndup */
+
+/* "Checked" memcpy */
+void *__memcpy_chk(void *dest, const void *src, size_t len, size_t destlen)
+{
+ assert(dest != NULL);
+ assert(src != NULL);
+ assert(len <= destlen);
+ if(src < dest)
+ {
+ assert(!(src + len >= dest));
+ } else {
+ assert(!(dest + len >= src));
+ }
+ return memcpy(dest, src, len);
+}
+
+/* "Checked" strncat */
+char *__strncat_chk(char *dest, const char *src, size_t n, size_t destlen)
+{
+ assert(dest != NULL);
+ assert(src != NULL);
+ assert(n <= destlen);
+
+ return strncat(dest, src, n);
+}
+
+/* "Checked" strcpy */
+char *__strcpy_chk(char *dest, const char *src, size_t destlen)
+{
+ assert(dest != NULL);
+ assert(src != NULL);
+ assert(strlen(src) < destlen);
+
+ return strcpy(dest, src);
+}
/* Literally a useless __ alias. */
char *__strndup(const char *str, size_t count)