Changed strcpy() to strncpy(). Let's build on Windows!

This commit is contained in:
Pietro Gagliardi 2019-05-31 02:58:57 -04:00
parent 1814745646
commit 664cf26cdc
2 changed files with 12 additions and 6 deletions

View File

@ -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;
}

View File

@ -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);
}
}