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 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/coregrind/m_libcprint.c b/coregrind/m_libcprint.c
index 549e7d7..1325856 100644
--- a/coregrind/m_libcprint.c
+++ b/coregrind/m_libcprint.c
@@ -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];
          }
diff --git a/coregrind/m_main.c b/coregrind/m_main.c
index 6542600..2a0b2a6 100644
--- a/coregrind/m_main.c
+++ b/coregrind/m_main.c
@@ -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"
diff --git a/coregrind/pub_core_libcprint.h b/coregrind/pub_core_libcprint.h
index ef086da..c9adb0b 100644
--- a/coregrind/pub_core_libcprint.h
+++ b/coregrind/pub_core_libcprint.h
@@ -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. */