This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix handling of era in strftime (month off-by-one error)


Hi, All.

I found a bug in the handling of era in strftime (month off-by-one error).

In the era info database (lc_era.h in cygwin),
the range of the month part is from 1 to 12.
(Ex: the era format in lc_era.h is like "1989/12/31")
But the range of tm_mon is from 0 to 11,
and strftime doesn't treat it.

Signed-off-by: Akio Idehara <zbe64533@gmail.com>
---
  libc/time/strftime.c |    6 +++---
  1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/libc/time/strftime.c b/libc/time/strftime.c
index f4704b6..840e310 100755
--- a/libc/time/strftime.c
+++ b/libc/time/strftime.c
@@ -426,7 +426,7 @@ get_era_info (const struct tm *tim_p, const char *era)
        /* Adjust offset for negative gregorian dates. */
        if (stm.tm_year <= -YEAR_BASE)
        	++stm.tm_year;
-      stm.tm_mon = ERA_STRTOL (c + 1, &c, 10);
+      stm.tm_mon = ERA_STRTOL (c + 1, &c, 10) - 1;
        stm.tm_mday = ERA_STRTOL (c + 1, &c, 10);
        stm.tm_hour = stm.tm_min = stm.tm_sec = 0;
        era = c + 1;
@@ -440,7 +440,7 @@ get_era_info (const struct tm *tim_p, const char *era)
        else if (era[0] == '+' && era[1] == '*')
  	{
  	  etm.tm_year = INT_MAX;
-	  etm.tm_mon = 12;
+	  etm.tm_mon = 11;
  	  etm.tm_mday = 31;
  	  etm.tm_hour = 23;
  	  etm.tm_min = etm.tm_sec = 59;
@@ -452,7 +452,7 @@ get_era_info (const struct tm *tim_p, const char *era)
  	  /* Adjust offset for negative gregorian dates. */
  	  if (etm.tm_year <= -YEAR_BASE)
  	    ++etm.tm_year;
-	  etm.tm_mon = ERA_STRTOL (c + 1, &c, 10);
+	  etm.tm_mon = ERA_STRTOL (c + 1, &c, 10) - 1;
  	  etm.tm_mday = ERA_STRTOL (c + 1, &c, 10);
  	  etm.tm_mday = 31;
  	  etm.tm_hour = 23;
--
1.7.5.1


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]