Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd1c2446

Browse files
committed
Fix cast-away-const problem as well as bogus calculation of required buffer size.
1 parent66bb74d commitd1c2446

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/1515:34:07 meskes Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/misc.c,v 1.46 2008/12/1519:07:48 tgl Exp $ */
22

33
#definePOSTGRES_ECPG_INTERNAL
44
#include"postgres_fe.h"
@@ -242,31 +242,36 @@ ecpg_log(const char *format,...)
242242
{
243243
va_listap;
244244
structsqlca_t*sqlca=ECPGget_sqlca();
245-
intbufsize=strlen(format)+100;
246-
char*f= (char*)malloc(bufsize),
247-
*intl_format;
245+
constchar*intl_format;
246+
intbufsize;
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
#ifdefENABLE_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)

[8]ページ先頭

©2009-2025 Movatter.jp