MCPcopy Index your code
hub / github.com/MapServer/MapServer / _ms_vsprintf

Function _ms_vsprintf

mapio.c:246–305  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

244/************************************************************************/
245
246static int _ms_vsprintf(char **workBufPtr, const char *format, va_list ap )
247
248{
249 int ret_val;
250 int workBufSize = 16000;
251
252 *workBufPtr = (char*)malloc(workBufSize * sizeof(char));
253 if (*workBufPtr == NULL)
254 {
255 msSetError( MS_MEMERR, NULL, "_ms_vsprintf()");
256 return -1;
257 }
258
259#if defined(HAVE_VSNPRINTF)
260 /* This should grow a big enough buffer to hold any formatted result. */
261 {
262 va_list wrk_args;
263
264#ifdef va_copy
265 va_copy( wrk_args, ap );
266#else
267 wrk_args = ap;
268#endif
269
270 while( (ret_val = vsnprintf( *workBufPtr, workBufSize,
271 format, wrk_args)) >= workBufSize-1
272 || ret_val == -1 )
273 {
274 workBufSize *= 4;
275 *workBufPtr = (char *) realloc(*workBufPtr, workBufSize );
276 if (*workBufPtr == NULL)
277 {
278 msSetError( MS_MEMERR, NULL, "_ms_vsprintf()");
279 va_end( wrk_args );
280 return -1;
281 }
282#ifdef va_copy
283 va_end( wrk_args );
284 va_copy( wrk_args, ap );
285#else
286 wrk_args = ap;
287#endif
288 }
289 va_end( wrk_args );
290 }
291#else
292 /* We do not have vsnprintf()... there is a risk of buffer overrun */
293 ret_val = vsprintf( *workBufPtr, format, ap );
294
295 if( ret_val < 0 || ret_val >= workBufSize )
296 {
297 msSetError(MS_MISCERR, "Possible buffer overrun.", "_ms_vsprintf()");
298 msFree(*workBufPtr);
299 *workBufPtr = NULL;
300 return -1;
301 }
302#endif
303

Callers 3

msIO_printfFunction · 0.85
msIO_fprintfFunction · 0.85
msIO_vfprintfFunction · 0.85

Calls 2

msSetErrorFunction · 0.85
msFreeFunction · 0.85

Tested by

no test coverage detected