From 5f011acc0c0619138f46dcefd8002fa2524d769c Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 9 Jun 2019 14:03:27 -0400 Subject: [PATCH] Somewhat hackily worked around strdup wonk. --- test/lib/testing.c | 12 ++++++++++ test/lib/testing.h | 4 ++++ test/noinitwrongthread.c | 50 ++-------------------------------------- 3 files changed, 18 insertions(+), 48 deletions(-) diff --git a/test/lib/testing.c b/test/lib/testing.c index c288086c..724060a6 100644 --- a/test/lib/testing.c +++ b/test/lib/testing.c @@ -312,3 +312,15 @@ void testingTRun(testingT *t, const char *subname, void (*subfunc)(testingT *t, testingprivFree(fullName); } + +// Utility functions, provided here to avoid mucking up the sharedbits functions. + +char *testingUtilStrdup(const char *s) +{ + return testingprivStrdup(s); +} + +void testingUtilFreeStrdup(char *s) +{ + testingprivFree(s); +} diff --git a/test/lib/testing.h b/test/lib/testing.h index 3e67b0e2..2690f3ba 100644 --- a/test/lib/testing.h +++ b/test/lib/testing.h @@ -100,3 +100,7 @@ sharedbitsPrintfFunc( 5, 6); #undef sharedbitsPrintfFunc extern void testingprivTLogvfFullThen(testingT *, void (*)(testingT *), const char *, long, const char *, va_list); + +// Utility functions, provided here to avoid mucking up the sharedbits functions. +extern char *testingUtilStrdup(const char *s); +extern void testingUtilFreeStrdup(char *s); diff --git a/test/noinitwrongthread.c b/test/noinitwrongthread.c index 67c83cb7..beb55416 100644 --- a/test/noinitwrongthread.c +++ b/test/noinitwrongthread.c @@ -11,45 +11,6 @@ struct errorCase { struct errorCase *next; }; -static struct errorCase *current = NULL; -static char *caseError = NULL; -static char caseErrorMemoryExhausted[] = "memory exhausted"; -static char caseErrorEncodingError[] = "encoding error while handling other case error"; - -#define sharedbitsPrefix priv -#define sharedbitsStatic static -#ifdef _WIN32 -// While we do only need strncpy(), our privInternalError() calls vsnprintf(), so include that too. -#include "../../sharedbits/strsafe_impl.h" -static void privInternalError(const char *fmt, ...) -{ - va_list ap, ap2; - int n; - - va_start(ap, fmt); - va_copy(ap2, ap); - n = privVsnprintf(NULL, 0, fmt, ap2); - va_end(ap2); - if (n < 0) { - caseError = caseErrorEncodingError; - va_end(ap); - return; - } - caseError = (char *) malloc((n + 1) * sizeof (char)); - if (caseError == NULL) { - caseError = caseErrorMemoryExhausted; - va_end(ap); - return; - } - privVsnprintf(caseError, n + 1, fmt, ap); - va_end(ap); -} -#else -#include "../../sharedbits/strsafe_strncpy_impl.h" -#endif -#undef sharedbitsStatic -#undef sharedbitsPrefix - static void catalogProgrammerError(const char *msg, void *data) { static struct errorCase *c; @@ -58,14 +19,7 @@ static void catalogProgrammerError(const char *msg, void *data) c->caught = true; if (strcmp(msg, c->msgWant) != 0) { n = strlen(msg); - c->msgGot = (char *) malloc((n + 1) * sizeof (char)); - if (c->msgGot == NULL) { - caseError = caseErrorMemoryExhausted; - return; - } - privStrncpy(c->msgGot, msg, n + 1); - if (caseError != NULL) - return; + c->msgGot = testingUtilStrdup(msg); } } @@ -89,7 +43,7 @@ static void freeCases(struct errorCase *first) p = first; while (p != NULL) { if (p->msgGot != NULL) - free(p->msgGot); + testingUtilFreeStrdup(p->msgGot); next = p->next; free(p); p = next;