Skip to content

Commit d1c2446

Browse files
committed
Fix cast-away-const problem as well as bogus calculation of required buffer size.
1 parent 66bb74d commit d1c2446

File tree

1 file changed

+16
-11
lines changed
  • src/interfaces/ecpg/ecpglib

1 file changed

+16
-11
lines changed

src/interfaces/ecpg/ecpglib/misc.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.45 2008/12/15 15:34:07 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.46 2008/12/15 19:07:48 tgl Exp $ */
22

33
#define POSTGRES_ECPG_INTERNAL
44
#include "postgres_fe.h"
@@ -242,31 +242,36 @@ ecpg_log(const char *format,...)
242242
{
243243
va_list ap;
244244
struct sqlca_t *sqlca = ECPGget_sqlca();
245-
int bufsize = strlen(format) + 100;
246-
char *f = (char *) malloc(bufsize),
247-
*intl_format;
245+
const char *intl_format;
246+
int bufsize;
247+
char *fmt;
248248

249-
if (!simple_debug || f == NULL)
249+
if (!simple_debug)
250250
return;
251251

252252
/* internationalize the error message string */
253253
intl_format = ecpg_gettext(format);
254254

255255
/*
256-
* regression tests set this environment variable to get the same
257-
* output for every run.
256+
* Insert PID into the format, unless ecpg_internal_regression_mode is
257+
* set (regression tests want unchanging output).
258258
*/
259+
bufsize = strlen(intl_format) + 100;
260+
fmt = (char *) malloc(bufsize);
261+
if (fmt == NULL)
262+
return;
263+
259264
if (ecpg_internal_regression_mode)
260-
snprintf(f, bufsize, "[NO_PID]: %s", intl_format);
265+
snprintf(fmt, bufsize, "[NO_PID]: %s", intl_format);
261266
else
262-
snprintf(f, bufsize, "[%d]: %s", (int) getpid(), intl_format);
267+
snprintf(fmt, bufsize, "[%d]: %s", (int) getpid(), intl_format);
263268

264269
#ifdef ENABLE_THREAD_SAFETY
265270
pthread_mutex_lock(&debug_mutex);
266271
#endif
267272

268273
va_start(ap, format);
269-
vfprintf(debugstream, f, ap);
274+
vfprintf(debugstream, fmt, ap);
270275
va_end(ap);
271276

272277
/* dump out internal sqlca variables */
@@ -280,7 +285,7 @@ ecpg_log(const char *format,...)
280285
pthread_mutex_unlock(&debug_mutex);
281286
#endif
282287

283-
free(f);
288+
free(fmt);
284289
}
285290

286291
void

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy