strftime(): Need null-termination on generated string. From Max Holtzberg

This commit is contained in:
Gregory Nutt 2013-12-12 17:41:07 -06:00
parent c0367fcc0a
commit 2fac3de49e
2 changed files with 12 additions and 3 deletions

View File

@ -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).

View File

@ -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;
}