aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-12-15 19:07:48 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-12-15 19:07:48 +0000
commitd1c24460bf40eb845b4675542fddeb1a62451dfe (patch)
tree00b68926bdc038b1ff377a33b4c09a3698eceb27 /src
parent66bb74dbe8206a35433d7cb0c47d82248a019802 (diff)
downloadpostgresql-d1c24460bf40eb845b4675542fddeb1a62451dfe.tar.gz
postgresql-d1c24460bf40eb845b4675542fddeb1a62451dfe.zip
Fix cast-away-const problem as well as bogus calculation of required buffer size.
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/ecpg/ecpglib/misc.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/interfaces/ecpg/ecpglib/misc.c b/src/interfaces/ecpg/ecpglib/misc.c
index 3125a9065c8..914ebe7a47d 100644
--- a/src/interfaces/ecpg/ecpglib/misc.c
+++ b/src/interfaces/ecpg/ecpglib/misc.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.45 2008/12/15 15:34:07 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.46 2008/12/15 19:07:48 tgl Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
@@ -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