File tree Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Expand file tree Collapse file tree 1 file changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -1186,20 +1186,30 @@ int pg_fputs(const char *s, FILE *stream)
1186
1186
}
1187
1187
1188
1188
/* replacement to puts function which uses flushBuffer */
1189
- int pg_puts (const char * tmps )
1189
+ int pg_puts (const char * s )
1190
1190
{
1191
1191
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 ;
1197
1205
target .nchars = 0 ;
1198
- target .bufptr = s + strlen ( s ) ;
1206
+ target .bufptr = t + len + 1 ;
1199
1207
target .bufend = NULL ;
1200
1208
target .failed = false;
1201
1209
target .stream = stdout ;
1202
1210
flushbuffer (& target );
1211
+
1212
+ free (t );
1203
1213
return target .failed ? -1 : target .nchars ;
1204
1214
}
1205
1215
#endif
You can’t perform that action at this time.
0 commit comments