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
+2
View File
@@ -6208,4 +6208,6 @@
From Ken Pettit (2013-12-12) From Ken Pettit (2013-12-12)
* arch/arm/src/a1x/chip/a1x_timer.h: Timer register bit definitions * arch/arm/src/a1x/chip/a1x_timer.h: Timer register bit definitions
(incomplete on initial check-in) (2013-12-12). (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).
+8 -1
View File
@@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* libc/time/lib_strftime.c * 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> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -394,5 +394,12 @@ size_t strftime(char *s, size_t max, const char *format, const struct tm *tm)
chleft -= len; chleft -= len;
} }
/* Append terminating null byte (if there is space for it) */
if (chleft > 0)
{
*dest = '\0';
}
return max - chleft; return max - chleft;
} }