Skip to content

Commit 48fa357

Browse files
committed
Fix vcregress check
1 parent ceca852 commit 48fa357

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/port/snprintf.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,20 +1186,30 @@ int pg_fputs(const char *s, FILE *stream)
11861186
}
11871187

11881188
/* replacement to puts function which uses flushBuffer */
1189-
int pg_puts(const char *tmps)
1189+
int pg_puts(const char *s)
11901190
{
11911191
PrintfTarget target;
1192-
char *s = NULL;
1193-
1194-
s = (char *)malloc(strlen(tmps) + 1);
1195-
sprintf(s, "%s\n", tmps);
1196-
target.bufstart = s;
1192+
char *t = NULL;
1193+
size_t len = strlen(s);
1194+
1195+
t = (char *)malloc(len + 2);
1196+
if (t == NULL) {
1197+
return -1;
1198+
}
1199+
1200+
memcpy(t,s,len);
1201+
t[len] = '\n';
1202+
t[len+1] = '\0';
1203+
1204+
target.bufstart = t;
11971205
target.nchars = 0;
1198-
target.bufptr = s + strlen(s);
1206+
target.bufptr = t + len + 1;
11991207
target.bufend = NULL;
12001208
target.failed = false;
12011209
target.stream = stdout;
12021210
flushbuffer(&target);
1211+
1212+
free(t);
12031213
return target.failed ? -1 : target.nchars;
12041214
}
12051215
#endif

0 commit comments

Comments
 (0)