]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Fix assert message to avoid printing garbage
authorMichael Meffie <mmeffie@sinenomine.net>
Wed, 15 Jul 2009 16:46:56 +0000 (12:46 -0400)
committerDerrick Brashear <shadow|account-1000005@unknown>
Thu, 17 Dec 2009 06:29:56 +0000 (22:29 -0800)
Fix an off by one error in assert() to avoid printing garbage
characters to the log. Remove the newline character generated by
ctime() to match the format generated by the other logging functions.

FIXES 124613

Reviewed-on: http://gerrit.openafs.org/102
Verified-by: Russ Allbery <rra@stanford.edu>
Reviewed-by: Russ Allbery <rra@stanford.edu>
(cherry picked from commit 15d203c7be957ba0e63288e2d95cbd078d94eb21)
Change-Id: I4720285db68f30730f67d62978d777fd6857fc7a
Reviewed-on: http://gerrit.openafs.org/931
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
src/util/assert.c

index e8f6d5639fd58a0e003c54daf0417762d321807c..11a2e039c676e127a9bf0903a01891435b0c5edc 100644 (file)
@@ -28,16 +28,19 @@ afs_NTAbort(void)
 }
 #endif
 
+#define TIMESTAMP_BUFFER_SIZE 26  /* including the null */
+#define TIMESTAMP_NEWLINE_POS 24  /* offset to the newline placed by ctime */
 
 void
 AssertionFailed(char *file, int line)
 {
-    char tdate[26];
+    char tdate[TIMESTAMP_BUFFER_SIZE];
     time_t when;
 
     time(&when);
-    (void)afs_ctime(&when, tdate, 25);
-    fprintf(stderr, "%s: Assertion failed! file %s, line %d.\n", tdate, file,
+    (void)afs_ctime(&when, tdate, sizeof(tdate));
+    tdate[TIMESTAMP_NEWLINE_POS] = ' ';
+    fprintf(stderr, "%sAssertion failed! file %s, line %d.\n", tdate, file,
            line);
     fflush(stderr);
 #ifdef AFS_NT40_ENV