Commit 1b912be158fa98556c9b3e79d936563bd80ac405
1 parent
ce0ef87d
Exists in
master
and in
3 other branches
Removendo warnings
Showing
1 changed file
with
29 additions
and
11 deletions
Show diff stats
util.c
... | ... | @@ -219,22 +219,40 @@ LIB3270_EXPORT const char * lib3270_win32_local_charset(void) |
219 | 219 | */ |
220 | 220 | char * lib3270_vsprintf(const char *fmt, va_list args) |
221 | 221 | { |
222 | - char *r; | |
223 | -#if defined(HAVE_VASPRINTF) /*[*/ | |
224 | - (void) vasprintf(&r, fmt, args); | |
225 | - if(!r) | |
222 | + char *r = NULL; | |
223 | + | |
224 | +#if defined(HAVE_VASPRINTF) | |
225 | + | |
226 | + if(vasprintf(&r, fmt, args) < 0 || !r) | |
226 | 227 | Error(NULL,"Out of memory in %s",__FUNCTION__); |
227 | - return r; | |
228 | -#else /*][*/ | |
228 | + | |
229 | +#else | |
230 | + | |
229 | 231 | char buf[16384]; |
230 | 232 | int nc; |
231 | 233 | |
232 | 234 | nc = vsnprintf(buf, sizeof(buf), fmt, args); |
233 | - if (nc > sizeof(buf)) | |
234 | - Error(NULL,"Internal buffer overflow"); | |
235 | - r = lib3270_malloc(nc + 1); | |
236 | - return strcpy(r, buf); | |
237 | -#endif /*]*/ | |
235 | + if(nc < 0) | |
236 | + { | |
237 | + Error(NULL,"Out of memory in %s",__FUNCTION__); | |
238 | + } | |
239 | + else if (nc < sizeof(buf)) | |
240 | + { | |
241 | + r = lib3270_malloc(nc + 1); | |
242 | + strcpy(r, buf); | |
243 | + | |
244 | + } | |
245 | + else | |
246 | + { | |
247 | + r = lib3270_malloc(nc + 1); | |
248 | + if(vsnprintf(r, nc, fmt, args) < 0) | |
249 | + Error(NULL,"Out of memory in %s",__FUNCTION__); | |
250 | + | |
251 | + } | |
252 | + | |
253 | +#endif | |
254 | + | |
255 | + return r; | |
238 | 256 | } |
239 | 257 | |
240 | 258 | LIB3270_EXPORT char * lib3270_strdup_printf(const char *fmt, ...) | ... | ... |