@@ -249,26 +249,21 @@ static void NOINLINE SharedPrintfCodeNoBuffer(bool append_pid,
249
249
va_list args) {
250
250
va_list args2;
251
251
va_copy (args2, args);
252
- const int kLen = 16 * 1024 ;
253
- int needed_length;
252
+ InternalMmapVector< char > v ;
253
+ int needed_length = 0 ;
254
254
char *buffer = local_buffer;
255
255
// First try to print a message using a local buffer, and then fall back to
256
256
// mmaped buffer.
257
- for (int use_mmap = 0 ; use_mmap < 2 ; use_mmap++) {
257
+ for (int use_mmap = 0 ;; use_mmap++) {
258
258
if (use_mmap) {
259
259
va_end (args);
260
260
va_copy (args, args2);
261
- buffer = (char *)MmapOrDie (kLen , " Report" );
262
- buffer_size = kLen ;
261
+ v.resize (needed_length + 1 );
262
+ buffer_size = v.capacity ();
263
+ v.resize (buffer_size);
264
+ buffer = &v[0 ];
263
265
}
264
266
needed_length = 0 ;
265
- // Check that data fits into the current buffer.
266
- # define CHECK_NEEDED_LENGTH \
267
- if (needed_length >= buffer_size) { \
268
- if (!use_mmap) continue ; \
269
- RAW_CHECK_MSG (needed_length < kLen , \
270
- " Buffer in Report is too short!\n " ); \
271
- }
272
267
// Fuchsia's logging infrastructure always keeps track of the logging
273
268
// process, thread, and timestamp, so never prepend such information.
274
269
if (!SANITIZER_FUCHSIA && append_pid) {
@@ -277,18 +272,20 @@ static void NOINLINE SharedPrintfCodeNoBuffer(bool append_pid,
277
272
if (common_flags ()->log_exe_name && exe_name) {
278
273
needed_length += internal_snprintf (buffer, buffer_size,
279
274
" ==%s" , exe_name);
280
- CHECK_NEEDED_LENGTH
275
+ if (needed_length >= buffer_size)
276
+ continue ;
281
277
}
282
278
needed_length += internal_snprintf (
283
279
buffer + needed_length, buffer_size - needed_length, " ==%d==" , pid);
284
- CHECK_NEEDED_LENGTH
280
+ if (needed_length >= buffer_size)
281
+ continue ;
285
282
}
286
283
needed_length += VSNPrintf (buffer + needed_length,
287
284
buffer_size - needed_length, format, args);
288
- CHECK_NEEDED_LENGTH
285
+ if (needed_length >= buffer_size)
286
+ continue ;
289
287
// If the message fit into the buffer, print it and exit.
290
288
break ;
291
- # undef CHECK_NEEDED_LENGTH
292
289
}
293
290
RawWrite (buffer);
294
291
@@ -297,9 +294,6 @@ static void NOINLINE SharedPrintfCodeNoBuffer(bool append_pid,
297
294
CallPrintfAndReportCallback (buffer);
298
295
LogMessageOnPrintf (buffer);
299
296
300
- // If we had mapped any memory, clean up.
301
- if (buffer != local_buffer)
302
- UnmapOrDie ((void *)buffer, buffer_size);
303
297
va_end (args2);
304
298
}
305
299
0 commit comments