1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
From: =?utf-8?b?0L3QsNCx?= <nabijaczleweli@nabijaczleweli.xyz>
Date: Sun, 20 Oct 2024 22:04:22 +0200
Bug-Debian: https://bugs.debian.org/827498
Subject: Don't leave uninitialised data after scan_date(). Don't segfault if
month=0
---
bdengine.c | 1 +
birthday.h | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/bdengine.c b/bdengine.c
index 30b7b88..7b1f8d7 100644
--- a/bdengine.c
+++ b/bdengine.c
@@ -439,6 +439,7 @@ unsigned delta(struct date *date, const struct date *today)
void scan_date( const char *str, struct date *date) {
int n;
+ date->day = date->month = date->year = 0;
n = sscanf(str, "%d/%d/%d", &(date->day), &(date->month), &(date->year));
if ( n < 3 ) {
/* didn't read the year */
diff --git a/birthday.h b/birthday.h
index 0106701..d4f0dcf 100644
--- a/birthday.h
+++ b/birthday.h
@@ -58,7 +58,7 @@
#define isleapyear(y) ((y)%4==0 && ((y)%100 != 0 || (y)%400 == 0))
extern const unsigned MLENDAT[];
-#define mlen(m,y) (MLENDAT[(m)-1] != -1 ? MLENDAT[(m)-1] : (isleapyear((y)) ? 29 : 28))
+#define mlen(m,y) (MLENDAT[(m?:1)-1] != -1 ? MLENDAT[(m?:1)-1] : (isleapyear((y)) ? 29 : 28))
#define before(a,b) ((a).month < (b).month || ((a).month == (b).month && (a).day < (b).day))
#define ydelta(a,b) ((int) (b).year - (a).year + before((a),(b)))
#define warnperiod(ev) ((ev).warn<iMinWarn?iMinWarn:((ev).warn>iMaxWarn?iMaxWarn:(ev).warn))
|