From 4fae6625754cf9adb371bb1b9a04189fa9a794ff Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 9 Feb 2020 20:49:47 -0500 Subject: [PATCH] Revert "Started restructuring common/errors.c to only produce a single error string (so we can pass it to Haiku's debugger() function without further allocations). In this case, the buffer size is 256 + the size of the prefix + the size of the suffix now." Okay, this is actually going to be more complicated than I at first thought... This reverts commit 44e13e53bffc896840412dc5620548fac768b39d. --- common/errors.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/common/errors.c b/common/errors.c index 94ce0c0b..c7a8448d 100644 --- a/common/errors.c +++ b/common/errors.c @@ -2,27 +2,22 @@ #include "uipriv.h" #include "testhooks.h" -#define maxErrorBuf 256 -#define conststrlen(s) ((sizeof (s) / sizeof (char)) - 1) -#define errorBufSize(prefix, suffix) (conststrlen(prefix) + maxErrorBuf + conststrlen(suffix) + 1) - #define internalErrorPrefix "libui internal error" // TODO add debugging advice? #define internalErrorSuffix "This likely means there is a bug in libui itself. Contact the libui authors." -#define internalErrorBufSize errorBufSize(internalErrorPrefix, internalErrorSuffix) void uiprivInternalError(const char *fmt, ...) { va_list ap; - char buf[internalErrorBufSize]; + char buf[256]; int n; va_start(ap, fmt); - n = uiprivVsnprintf(buf, internalErrorBufSize, fmt, ap); + n = uiprivVsnprintf(buf, 256, fmt, ap); va_end(ap); if (n < 0) uiprivReportError(internalErrorPrefix, "internal error string has encoding error", internalErrorSuffix, true); - if (n >= internalErrorBufSize) + if (n >= 256) uiprivReportError(internalErrorPrefix, "internal error string too long", internalErrorSuffix, true); uiprivReportError(internalErrorPrefix, buf, internalErrorSuffix, true); } @@ -30,7 +25,6 @@ void uiprivInternalError(const char *fmt, ...) #define programmerErrorPrefix "libui programmer error" // TODO add debugging advice? #define programmerErrorSuffix "This likely means you are using libui incorrectly. Check your source code and try again. If you have received this warning in error, contact the libui authors." -#define programmerErrorBufSize errorBufSize(programmerErrorPrefix, programmerErrorSuffix) static uiprivTestHookReportProgrammerErrorFunc reportProgrammerErrorTestHook = NULL; static void *reportProgrammerErrorTestHookData = NULL; @@ -44,14 +38,14 @@ void uiprivTestHookReportProgrammerError(uiprivTestHookReportProgrammerErrorFunc void uiprivProgrammerError(const char *fmt, ...) { va_list ap; - char buf[programmerErrorBufSize]; int n; + char buf[256]; va_start(ap, fmt); - n = uiprivVsnprintf(buf, programmerErrorBufSize, fmt, ap); + n = uiprivVsnprintf(buf, 256, fmt, ap); if (n < 0) uiprivInternalError("programmer error has encoding error"); - if (n >= programmerErrorBufSize) + if (n >= 256) uiprivInternalError("programmer error string too long (%d)", n); va_end(ap); if (reportProgrammerErrorTestHook != NULL) {