From: Florian Krohm Date: Fri, 14 Nov 2014 22:34:40 +0000 (+0000) Subject: Pass buffer size to VG_(elapsed_wallclock_time) so the function X-Git-Tag: svn/VALGRIND_3_11_0~824 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff084222338f6e761eab23586de260790aff1f42;p=thirdparty%2Fvalgrind.git Pass buffer size to VG_(elapsed_wallclock_time) so the function can check it's large enough. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14724 --- diff --git a/coregrind/m_libcprint.c b/coregrind/m_libcprint.c index 549e7d7e88..13258568b5 100644 --- a/coregrind/m_libcprint.c +++ b/coregrind/m_libcprint.c @@ -424,10 +424,12 @@ void VG_(percentify)(ULong n, ULong m, UInt d, Int n_buf, HChar buf[]) millisecond timer having been set to zero by an initial read in m_main during startup. */ -void VG_(elapsed_wallclock_time) ( /*OUT*/HChar* buf ) +void VG_(elapsed_wallclock_time) ( /*OUT*/HChar* buf, SizeT bufsize ) { UInt t, ms, s, mins, hours, days; + vg_assert(bufsize > 20); + t = VG_(read_millisecond_timer)(); /* milliseconds */ ms = t % 1000; @@ -534,9 +536,7 @@ static void add_to__vmessage_buf ( HChar c, void *p ) b->buf[b->buf_used++] = ch; if (VG_(clo_time_stamp)) { - VG_(memset)(tmp, 0, sizeof(tmp)); - VG_(elapsed_wallclock_time)(tmp); - tmp[sizeof(tmp)-1] = 0; + VG_(elapsed_wallclock_time)(tmp, sizeof tmp); for (i = 0; tmp[i]; i++) b->buf[b->buf_used++] = tmp[i]; } diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 6542600d01..2a0b2a6778 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -2208,7 +2208,7 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp ) if (VG_(clo_xml)) { HChar buf[50]; - VG_(elapsed_wallclock_time)(buf); + VG_(elapsed_wallclock_time)(buf, sizeof buf); VG_(printf_xml)( "\n" " RUNNING\n" " \n" @@ -2545,7 +2545,7 @@ void shutdown_actions_NORETURN( ThreadId tid, if (VG_(clo_xml)) { HChar buf[50]; - VG_(elapsed_wallclock_time)(buf); + VG_(elapsed_wallclock_time)(buf, sizeof buf); VG_(printf_xml)( "\n" " FINISHED\n" " \n" diff --git a/coregrind/pub_core_libcprint.h b/coregrind/pub_core_libcprint.h index ef086da9be..c9adb0b24f 100644 --- a/coregrind/pub_core_libcprint.h +++ b/coregrind/pub_core_libcprint.h @@ -48,11 +48,13 @@ typedef extern OutputSink VG_(log_output_sink); extern OutputSink VG_(xml_output_sink); -/* Get the elapsed wallclock time since startup into buf, which must - 16 chars long. This is unchecked. It also relies on the +/* Get the elapsed wallclock time since startup into buf which has size + bufsize. The function will assert if bufsize is not large enough. + Upon return, buf will contain the zero-terminated wallclock time as + a string. The function also relies on the millisecond timer having been set to zero by an initial read in m_main during startup. */ -void VG_(elapsed_wallclock_time) ( /*OUT*/HChar* buf ); +void VG_(elapsed_wallclock_time) ( /*OUT*/HChar* buf, SizeT bufsize ); /* Call this if the executable is missing. This function prints an error message, then shuts down the entire system. */