From: Tom Lane Date: Mon, 15 Dec 2008 19:07:48 +0000 (+0000) Subject: Fix cast-away-const problem as well as bogus calculation of required buffer size. X-Git-Tag: recoveryinfrav9~204 X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=256c933ca5788973c89af34924dff8e4a58f43d7;p=users%2Fsimon%2Fpostgres.git Fix cast-away-const problem as well as bogus calculation of required buffer size. --- diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c index a4fdddee80..28e04f74a7 100644 --- a/src/interfaces/ecpg/ecpglib/misc.c +++ b/src/interfaces/ecpg/ecpglib/misc.c @@ -242,31 +242,36 @@ ecpg_log(const char *format,...) { va_list ap; struct sqlca_t *sqlca = ECPGget_sqlca(); - int bufsize = strlen(format) + 100; - char *f = (char *) malloc(bufsize), - *intl_format; + const char *intl_format; + int bufsize; + char *fmt; - if (!simple_debug || f == NULL) + if (!simple_debug) return; /* internationalize the error message string */ intl_format = ecpg_gettext(format); /* - * regression tests set this environment variable to get the same - * output for every run. + * Insert PID into the format, unless ecpg_internal_regression_mode is + * set (regression tests want unchanging output). */ + bufsize = strlen(intl_format) + 100; + fmt = (char *) malloc(bufsize); + if (fmt == NULL) + return; + if (ecpg_internal_regression_mode) - snprintf(f, bufsize, "[NO_PID]: %s", intl_format); + snprintf(fmt, bufsize, "[NO_PID]: %s", intl_format); else - snprintf(f, bufsize, "[%d]: %s", (int) getpid(), intl_format); + snprintf(fmt, bufsize, "[%d]: %s", (int) getpid(), intl_format); #ifdef ENABLE_THREAD_SAFETY pthread_mutex_lock(&debug_mutex); #endif va_start(ap, format); - vfprintf(debugstream, f, ap); + vfprintf(debugstream, fmt, ap); va_end(ap); /* dump out internal sqlca variables */ @@ -280,7 +285,7 @@ ecpg_log(const char *format,...) pthread_mutex_unlock(&debug_mutex); #endif - free(f); + free(fmt); } void