mirror of
https://github.com/postgres/postgres.git
synced 2025-05-03 22:24:49 +03:00
Fix cast-away-const problem as well as bogus calculation of required buffer size.
This commit is contained in:
parent
66bb74dbe8
commit
d1c24460bf
@ -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
|
#define POSTGRES_ECPG_INTERNAL
|
||||||
#include "postgres_fe.h"
|
#include "postgres_fe.h"
|
||||||
@ -242,31 +242,36 @@ ecpg_log(const char *format,...)
|
|||||||
{
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
struct sqlca_t *sqlca = ECPGget_sqlca();
|
struct sqlca_t *sqlca = ECPGget_sqlca();
|
||||||
int bufsize = strlen(format) + 100;
|
const char *intl_format;
|
||||||
char *f = (char *) malloc(bufsize),
|
int bufsize;
|
||||||
*intl_format;
|
char *fmt;
|
||||||
|
|
||||||
if (!simple_debug || f == NULL)
|
if (!simple_debug)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* internationalize the error message string */
|
/* internationalize the error message string */
|
||||||
intl_format = ecpg_gettext(format);
|
intl_format = ecpg_gettext(format);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* regression tests set this environment variable to get the same
|
* Insert PID into the format, unless ecpg_internal_regression_mode is
|
||||||
* output for every run.
|
* set (regression tests want unchanging output).
|
||||||
*/
|
*/
|
||||||
|
bufsize = strlen(intl_format) + 100;
|
||||||
|
fmt = (char *) malloc(bufsize);
|
||||||
|
if (fmt == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
if (ecpg_internal_regression_mode)
|
if (ecpg_internal_regression_mode)
|
||||||
snprintf(f, bufsize, "[NO_PID]: %s", intl_format);
|
snprintf(fmt, bufsize, "[NO_PID]: %s", intl_format);
|
||||||
else
|
else
|
||||||
snprintf(f, bufsize, "[%d]: %s", (int) getpid(), intl_format);
|
snprintf(fmt, bufsize, "[%d]: %s", (int) getpid(), intl_format);
|
||||||
|
|
||||||
#ifdef ENABLE_THREAD_SAFETY
|
#ifdef ENABLE_THREAD_SAFETY
|
||||||
pthread_mutex_lock(&debug_mutex);
|
pthread_mutex_lock(&debug_mutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
va_start(ap, format);
|
va_start(ap, format);
|
||||||
vfprintf(debugstream, f, ap);
|
vfprintf(debugstream, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
/* dump out internal sqlca variables */
|
/* dump out internal sqlca variables */
|
||||||
@ -280,7 +285,7 @@ ecpg_log(const char *format,...)
|
|||||||
pthread_mutex_unlock(&debug_mutex);
|
pthread_mutex_unlock(&debug_mutex);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
free(f);
|
free(fmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user