Skip to content

Commit 57a7b30

Browse files
Potential fix for code scanning alert no. 83: Potentially overrunning write
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 8559dba commit 57a7b30

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

cores/esp32/esp32-hal-time.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ static void setTimeZone(long offset, int daylight) {
2727
char tz[33] = {0};
2828

2929
if (offset % 3600) {
30-
sprintf(cst, "UTC%ld:%02u:%02u", offset / 3600, abs((offset % 3600) / 60), abs(offset % 60));
30+
snprintf(cst, sizeof(cst), "UTC%ld:%02u:%02u", offset / 3600, abs((offset % 3600) / 60), abs(offset % 60));
3131
} else {
32-
sprintf(cst, "UTC%ld", offset / 3600);
32+
snprintf(cst, sizeof(cst), "UTC%ld", offset / 3600);
3333
}
3434
if (daylight != 3600) {
3535
long tz_dst = offset - daylight;
3636
if (tz_dst % 3600) {
37-
sprintf(cdt, "DST%ld:%02u:%02u", tz_dst / 3600, abs((tz_dst % 3600) / 60), abs(tz_dst % 60));
37+
snprintf(cdt, sizeof(cdt), "DST%ld:%02u:%02u", tz_dst / 3600, abs((tz_dst % 3600) / 60), abs(tz_dst % 60));
3838
} else {
39-
sprintf(cdt, "DST%ld", tz_dst / 3600);
39+
snprintf(cdt, sizeof(cdt), "DST%ld", tz_dst / 3600);
4040
}
4141
}
42-
sprintf(tz, "%s%s", cst, cdt);
42+
snprintf(tz, sizeof(tz), "%s%s", cst, cdt);
4343
setenv("TZ", tz, 1);
4444
tzset();
4545
}

0 commit comments

Comments
 (0)