aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2011-04-11 16:47:23 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2011-04-12 12:02:39 +0200
commit3a4431e5687cc45e2f3a774c8ea782aaef47efdd (patch)
tree61a850558e6b30ed5f04b91c2a30b9200b1316ad
parent5fc6d92866942fc46fb7d7e7147a97ad37615f7e (diff)
downloadcalcurse-3a4431e5687cc45e2f3a774c8ea782aaef47efdd.tar.gz
calcurse-3a4431e5687cc45e2f3a774c8ea782aaef47efdd.zip
Fix null pointer dereference in parse_date().
Passing a date in format "mm-dd-yy" where short forms are not allowed would lead to a null pointer dereference here. This one fixes that. Spotted by clang-analyzer. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r--src/utils.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/src/utils.c b/src/utils.c
index d21debe..22c5be9 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -843,16 +843,19 @@ parse_date (char *date_string, enum datefmt datefmt, int *year, int *month,
return 0;
}
- if (y > 0 && y < 100)
+ if (slctd_date)
{
- /* convert "YY" format into "YYYY" */
- y += slctd_date->yyyy - slctd_date->yyyy % 100;
- }
- else if (n < 2)
- {
- /* set year and, optionally, month if short from is used */
- y = slctd_date->yyyy;
- if (n < 1) m = slctd_date->mm;
+ if (y > 0 && y < 100)
+ {
+ /* convert "YY" format into "YYYY" */
+ y += slctd_date->yyyy - slctd_date->yyyy % 100;
+ }
+ else if (n < 2)
+ {
+ /* set year and, optionally, month if short from is used */
+ y = slctd_date->yyyy;
+ if (n < 1) m = slctd_date->mm;
+ }
}
/* check if date is valid, take leap years into account */