|
From: <sv...@va...> - 2014-11-14 22:34:48
|
Author: florian
Date: Fri Nov 14 22:34:40 2014
New Revision: 14724
Log:
Pass buffer size to VG_(elapsed_wallclock_time) so the function
can check it's large enough.
Modified:
trunk/coregrind/m_libcprint.c
trunk/coregrind/m_main.c
trunk/coregrind/pub_core_libcprint.h
Modified: trunk/coregrind/m_libcprint.c
==============================================================================
--- trunk/coregrind/m_libcprint.c (original)
+++ trunk/coregrind/m_libcprint.c Fri Nov 14 22:34:40 2014
@@ -424,10 +424,12 @@
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 @@
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];
}
Modified: trunk/coregrind/m_main.c
==============================================================================
--- trunk/coregrind/m_main.c (original)
+++ trunk/coregrind/m_main.c Fri Nov 14 22:34:40 2014
@@ -2208,7 +2208,7 @@
if (VG_(clo_xml)) {
HChar buf[50];
- VG_(elapsed_wallclock_time)(buf);
+ VG_(elapsed_wallclock_time)(buf, sizeof buf);
VG_(printf_xml)( "<status>\n"
" <state>RUNNING</state>\n"
" <time>%pS</time>\n"
@@ -2545,7 +2545,7 @@
if (VG_(clo_xml)) {
HChar buf[50];
- VG_(elapsed_wallclock_time)(buf);
+ VG_(elapsed_wallclock_time)(buf, sizeof buf);
VG_(printf_xml)( "<status>\n"
" <state>FINISHED</state>\n"
" <time>%pS</time>\n"
Modified: trunk/coregrind/pub_core_libcprint.h
==============================================================================
--- trunk/coregrind/pub_core_libcprint.h (original)
+++ trunk/coregrind/pub_core_libcprint.h Fri Nov 14 22:34:40 2014
@@ -48,11 +48,13 @@
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. */
|