diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-12-12 17:41:07 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-12-12 17:41:07 -0600 |
commit | 1f87e2b12a8ae387f184253e6d89dea0af7ea721 (patch) | |
tree | 63538b2bc0addc3e7121b483c239f350795471a0 /nuttx/libc | |
parent | 181c7d91e2f0dbdad7ce42881df48c21ed753d98 (diff) | |
download | px4-nuttx-1f87e2b12a8ae387f184253e6d89dea0af7ea721.tar.gz px4-nuttx-1f87e2b12a8ae387f184253e6d89dea0af7ea721.tar.bz2 px4-nuttx-1f87e2b12a8ae387f184253e6d89dea0af7ea721.zip |
strftime(): Need null-termination on generated string. From Max Holtzberg
Diffstat (limited to 'nuttx/libc')
-rw-r--r-- | nuttx/libc/time/lib_strftime.c | 13 |
1 files changed, 10 insertions, 3 deletions
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; } |