aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/patch-specs.sh
Commit message (Expand)AuthorAgeFilesLines
* [scripts] patch-specs.sh: gcc 3.4.6 has an additional "(OpenWrt-2.0)" after t...Jo-Philipp Wich2012-01-291-1/+1
* [scripts] patch-specs.sh: fallback to ext-toolchain.sh --wrap if spec file pa...Jo-Philipp Wich2012-01-291-35/+61
* [scripts] add patch-specs.sh, a utility for modifying GCC specsJo-Philipp Wich2012-01-181-0/+64
3'>13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
From bc1e7731cee963e422575f81048792f4d5db9641 Mon Sep 17 00:00:00 2001
From: Daniel Sabogal <dsabogal@ufl.edu>
Date: Wed, 2 Nov 2016 22:29:36 -0400
Subject: fix integer overflow of tm_year in __secs_to_tm

the overflow check for years+100 did not account for the extra
year computed from the remaining months. instead, perform this
check after obtaining the final number of years.
---
 src/time/__secs_to_tm.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/time/__secs_to_tm.c b/src/time/__secs_to_tm.c
index 3a3123a..093d902 100644
--- a/src/time/__secs_to_tm.c
+++ b/src/time/__secs_to_tm.c
@@ -60,15 +60,16 @@ int __secs_to_tm(long long t, struct tm *tm)
 	for (months=0; days_in_month[months] <= remdays; months++)
 		remdays -= days_in_month[months];
 
+	if (months >= 10) {
+		months -= 12;
+		years++;
+	}
+
 	if (years+100 > INT_MAX || years+100 < INT_MIN)
 		return -1;
 
 	tm->tm_year = years + 100;
 	tm->tm_mon = months + 2;
-	if (tm->tm_mon >= 12) {
-		tm->tm_mon -=12;
-		tm->tm_year++;
-	}
 	tm->tm_mday = remdays + 1;
 	tm->tm_wday = wday;
 	tm->tm_yday = yday;
-- 
cgit v0.11.2