From 19fe725976fddaf4b36ce92645099d9187a2674e Mon Sep 17 00:00:00 2001 From: Gary Langshaw Date: Wed, 7 Aug 2024 22:35:22 +0100 Subject: [PATCH] database.c: avoid undefined behaviour in FixDayDow() This issue was flagged by clang-static-analyser: mask |= 1 << (i - 1) will result in undefined behaviour when i == 0 as the lshift operand will be negative. As cl_Days[] only uses indices 1..31 we can avoid the potential issue by starting the iteration at index 1. --- database.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database.c b/database.c index ba71b93..2de2693 100644 --- a/database.c +++ b/database.c @@ -852,7 +852,7 @@ FixDayDow(CronLine *line) } } - for (i = 0; i < arysize(line->cl_Days); ++i) { + for (i = 1; i < arysize(line->cl_Days); ++i) { if (line->cl_Days[i] == 0) { /* '*' was NOT specified in the Date field on this CronLine */ DomStar = 0; @@ -865,7 +865,7 @@ FixDayDow(CronLine *line) return; /* Set individual bits within the DoW mask... */ - for (i = 0; i < arysize(line->cl_Days); ++i) { + for (i = 1; i < arysize(line->cl_Days); ++i) { if (line->cl_Days[i]) { if (i < 6) mask |= 1 << (i - 1);