From 664cf26cdc51f6c61e50c4fcb2977bc67f0ee46d Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 31 May 2019 02:58:57 -0400 Subject: [PATCH] Changed strcpy() to strncpy(). Let's build on Windows! --- test/lib/testingpriv.c | 6 ++++-- test/noinitwrongthread.c | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/test/lib/testingpriv.c b/test/lib/testingpriv.c index 1eaddd69..c478cff9 100644 --- a/test/lib/testingpriv.c +++ b/test/lib/testingpriv.c @@ -52,9 +52,11 @@ int testingprivSnprintf(char *s, size_t n, const char *format, ...) char *testingprivStrdup(const char *s) { char *t; + size_t n; - t = (char *) testingprivAlloc((strlen(s) + 1) * sizeof (char), "char[]"); - strcpy(t, s); + n = strlen(s); + t = (char *) testingprivAlloc((n + 1) * sizeof (char), "char[]"); + strncpy(t, s, n + 1); return t; } diff --git a/test/noinitwrongthread.c b/test/noinitwrongthread.c index 2378b1a3..52127379 100644 --- a/test/noinitwrongthread.c +++ b/test/noinitwrongthread.c @@ -19,23 +19,27 @@ static bool memoryExhausted = false; static void catalogProgrammerError(const char *prefix, const char *msg, const char *suffix, bool internal) { + size_t n; + current->caught = true; if (strstr(prefix, "programmer error") == NULL) { - current->prefixGot = (char *) malloc((strlen(prefix) + 1) * sizeof (char)); + n = strlen(prefix); + current->prefixGot = (char *) malloc((n + 1) * sizeof (char)); if (current->prefixGot == NULL) { memoryExhausted = true; return; } - strcpy(current->prefixGot, prefix); + strncpy(current->prefixGot, prefix, n + 1); } current->internalGot = internal; if (strstr(msg, current->msgWant) == NULL) { - current->msgGot = (char *) malloc((strlen(msg) + 1) * sizeof (char)); + n = strlen(msg); + current->msgGot = (char *) malloc((n + 1) * sizeof (char)); if (current->msgGot == NULL) { memoryExhausted = true; return; } - strcpy(current->msgGot, msg); + strncpy(current->msgGot, msg, n + 1); } }