summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nuttx/ChangeLog2
-rw-r--r--nuttx/libc/time/lib_strftime.c13
2 files changed, 12 insertions, 3 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index d60111213..fd407f53f 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -6208,4 +6208,6 @@
From Ken Pettit (2013-12-12)
* arch/arm/src/a1x/chip/a1x_timer.h: Timer register bit definitions
(incomplete on initial check-in) (2013-12-12).
+ * lbc/time/lib_strftime.c: Need null-termination on the the string
+ generated by strftime(). From Max Holtzberg (2013-12-12).
diff --git a/nuttx/libc/time/lib_strftime.c b/nuttx/libc/time/lib_strftime.c
index 3b0c8dd8f..81d63a627 100644
--- a/nuttx/libc/time/lib_strftime.c
+++ b/nuttx/libc/time/lib_strftime.c
@@ -1,7 +1,7 @@
/****************************************************************************
* libc/time/lib_strftime.c
*
- * Copyright (C) 2009, 2011 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2009, 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@@ -138,7 +138,7 @@ static const char * const g_monthname[12] =
* The strftime() function returns the number of characters placed in the
* array s, not including the terminating null byte, provided the string,
* including the terminating null byte, fits. Otherwise, it returns 0,
- * and the contents of the array is undefined.
+ * and the contents of the array is undefined.
*
****************************************************************************/
@@ -177,7 +177,7 @@ size_t strftime(char *s, size_t max, const char *format, const struct tm *tm)
len = snprintf(dest, chleft, "Day"); /* Not supported */
}
break;
-
+
/* %h: Equivalent to %b */
case 'h':
@@ -394,5 +394,12 @@ size_t strftime(char *s, size_t max, const char *format, const struct tm *tm)
chleft -= len;
}
+ /* Append terminating null byte (if there is space for it) */
+
+ if (chleft > 0)
+ {
+ *dest = '\0';
+ }
+
return max - chleft;
}