From 1473145d10a0ba529526897c08eab2fb176dac01 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Sun, 3 Apr 2011 21:11:18 +0200 Subject: Avoid assignment of undefined value in parse_date(). Spotted by clang-analyzer ("Assigned value is garbage or undefined"). Signed-off-by: Lukas Fleischer --- src/utils.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils.c b/src/utils.c index 6fc784c..8e4a447 100644 --- a/src/utils.c +++ b/src/utils.c @@ -824,8 +824,8 @@ parse_date (char *date_string, enum datefmt datefmt, int *year, int *month, switch (datefmt) { case DATEFMT_MMDDYYYY: - m = in[n > 0 ? 0 : 1]; - d = in[n > 0 ? 1 : 0]; + m = (n >= 1) ? in[0] : 0; + d = (n >= 1) ? in[1] : in[0]; y = in[2]; break; case DATEFMT_DDMMYYYY: @@ -835,8 +835,8 @@ parse_date (char *date_string, enum datefmt datefmt, int *year, int *month, break; case DATEFMT_YYYYMMDD: case DATEFMT_ISO: - y = in[0]; - m = in[n - 1]; + y = (n >= 2) ? in[n - 2] : 0; + m = (n >= 1) ? in[n - 1] : 0; d = in[n]; break; default: -- cgit v1.2.3-70-g09d2