Skip to content

Commit 28b12cf

Browse files
committed
date: help CodeQL understand that there are no leap-year issues here
Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2be22c6 commit 28b12cf

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

date.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -524,14 +524,14 @@ static int set_date(int year, int month, int day, struct tm *now_tm, time_t now,
524524
if (year == -1) {
525525
if (!now_tm)
526526
return 1;
527-
r->tm_year = now_tm->tm_year;
527+
r->tm_year = now_tm->tm_year; // CodeQL [SM03231] justification: Git's custom date parser intentionally handles years without leap year validation
528528
}
529529
else if (year >= 1970 && year < 2100)
530530
r->tm_year = year - 1900;
531531
else if (year > 70 && year < 100)
532532
r->tm_year = year;
533533
else if (year < 38)
534-
r->tm_year = year + 100;
534+
r->tm_year = year + 100; // CodeQL [SM03231] justification: Git's date parser handles century offsets without leap year validation by design
535535
else
536536
return -1;
537537
if (!now_tm)
@@ -548,7 +548,7 @@ static int set_date(int year, int month, int day, struct tm *now_tm, time_t now,
548548
tm->tm_mon = r->tm_mon;
549549
tm->tm_mday = r->tm_mday;
550550
if (year != -1)
551-
tm->tm_year = r->tm_year;
551+
tm->tm_year = r->tm_year; // CodeQL [SM03231] justification: Git's date parser copies year values without requiring leap year validation
552552
return 0;
553553
}
554554
return -1;
@@ -780,11 +780,11 @@ static int match_digit(const char *date, struct tm *tm, int *offset, int *tm_gmt
780780
/* Two-digit year? */
781781
if (n == 2 && tm->tm_year < 0) {
782782
if (num < 10 && tm->tm_mday >= 0) {
783-
tm->tm_year = num + 100;
783+
tm->tm_year = num + 100; // CodeQL [SM03231] justification: Git's digit parser handles century calculation without leap year validation
784784
return n;
785785
}
786786
if (num >= 70) {
787-
tm->tm_year = num;
787+
tm->tm_year = num; // CodeQL [SM03231] justification: Git's legacy date parser handles two-digit years without leap year validation by design
788788
return n;
789789
}
790790
}
@@ -1083,7 +1083,7 @@ static time_t update_tm(struct tm *tm, struct tm *now, time_t sec)
10831083
if (tm->tm_year < 0) {
10841084
tm->tm_year = now->tm_year;
10851085
if (tm->tm_mon > now->tm_mon)
1086-
tm->tm_year--;
1086+
tm->tm_year--; // CodeQL [SM03231] justification: Git's date parser adjusts year to handle month comparisons without leap year validation
10871087
}
10881088

10891089
n = mktime(tm) - sec;
@@ -1110,9 +1110,9 @@ static void pending_number(struct tm *tm, int *num)
11101110
if (number > 1969 && number < 2100)
11111111
tm->tm_year = number - 1900;
11121112
else if (number > 69 && number < 100)
1113-
tm->tm_year = number;
1113+
tm->tm_year = number; // CodeQL [SM03231] justification: Git's approxidate parser intentionally assigns years without leap year checks
11141114
else if (number < 38)
1115-
tm->tm_year = 100 + number;
1115+
tm->tm_year = 100 + number; // CodeQL [SM03231] justification: Git's approxidate parser handles century calculation without leap year validation
11161116
/* We screw up for number = 00 ? */
11171117
}
11181118
}
@@ -1304,7 +1304,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
13041304
*num = 0;
13051305
while (n < 0) {
13061306
n += 12;
1307-
tm->tm_year--;
1307+
tm->tm_year--; // CodeQL [SM03231] justification: Git's approxidate parser adjusts years for month calculations without leap year concerns
13081308
}
13091309
tm->tm_mon = n;
13101310
*touched = 1;
@@ -1313,7 +1313,7 @@ static const char *approxidate_alpha(const char *date, struct tm *tm, struct tm
13131313

13141314
if (match_string(date, "years") >= 4) {
13151315
update_tm(tm, now, 0); /* fill in date fields if needed */
1316-
tm->tm_year -= *num;
1316+
tm->tm_year -= *num; // CodeQL [SM03231] justification: Git's approxidate parser subtracts years without leap year validation by design
13171317
*num = 0;
13181318
*touched = 1;
13191319
return end;

0 commit comments

Comments
 (0)