From d0958e776ba9d44a1ddf07f5cec4faf3f83a33e0 Mon Sep 17 00:00:00 2001 From: ramiro Date: Thu, 4 Jun 1998 08:48:30 +0000 Subject: [PATCH] Fix problems (like core dumps) with static strings. Use malloc instead. --- cmd/xfe/XfeWidgets/Xfe/Debug.c | 42 +++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/cmd/xfe/XfeWidgets/Xfe/Debug.c b/cmd/xfe/XfeWidgets/Xfe/Debug.c index 9e1bff39156e..d3d589a82954 100644 --- a/cmd/xfe/XfeWidgets/Xfe/Debug.c +++ b/cmd/xfe/XfeWidgets/Xfe/Debug.c @@ -23,7 +23,6 @@ /* */ /*----------------------------------------------------------------------*/ - #ifdef DEBUG /* ifdef DEBUG */ #include @@ -32,14 +31,37 @@ #include #include +#define DEBUG_BUFFER_SIZE 2048 + +/* + * This memory will leak, but only in debug builds. + */ +static String +DebugGetBuffer(void) +{ + static String _debug_buffer = NULL; + + if (!_debug_buffer) + { + _debug_buffer = (String) XtMalloc(sizeof(char) * DEBUG_BUFFER_SIZE); + } + + assert( _debug_buffer != NULL ); + + return _debug_buffer; +} + +/*----------------------------------------------------------------------*/ + + /*----------------------------------------------------------------------*/ /* extern */ String XfeDebugXmStringToStaticPSZ(XmString xmstring) { - static char buf[2048]; + String result = DebugGetBuffer(); String psz_string; - buf[0] = '\0'; + result[0] = '\0'; if (xmstring) { @@ -47,13 +69,13 @@ XfeDebugXmStringToStaticPSZ(XmString xmstring) if (psz_string) { - strcpy(buf,psz_string); + strcpy(result,psz_string); XtFree(psz_string); } } - return buf; + return result; } /*----------------------------------------------------------------------*/ /* extern */ void @@ -78,7 +100,8 @@ XfeDebugPrintArgVector(FILE * fp, /* extern */ String XfeDebugRepTypeValueToName(String rep_type,unsigned char value) { - char * result = NULL; + String result = DebugGetBuffer(); + Boolean found = False; if (rep_type) { @@ -92,11 +115,13 @@ XfeDebugRepTypeValueToName(String rep_type,unsigned char value) { Cardinal i = 0; - while ((i < entry->num_values) && !result) + while ((i < entry->num_values) && !found) { if (entry->values[i] == value) { - result = XtNewString(entry->value_names[i]); + found = True; + + strcpy(result,entry->value_names[i]); } i++; @@ -133,6 +158,7 @@ XfeDebugRepTypeNameToValue(String rep_type,String name) if (strcmp(entry->value_names[i],name) == 0) { result = entry->values[i]; + found = True; }