Address #170 - strchr was not properly checking for 0 byte.

This commit is contained in:
Calvin Rose
2026-01-23 08:13:15 -06:00
parent c43e06672c
commit 0f285855f0
2 changed files with 7 additions and 4 deletions
+3 -3
View File
@@ -1922,7 +1922,7 @@ JANET_CORE_FN(os_date,
return janet_wrap_struct(janet_struct_end(st));
}
#define SIZETIMEFMT 250
#define SIZETIMEFMT 250
JANET_CORE_FN(os_strftime,
"(os/strftime fmt &opt time local)",
@@ -1937,7 +1937,7 @@ JANET_CORE_FN(os_strftime,
const char *p = fmt;
while (*p) {
if (*p++ == '%') {
if (!strchr(valid, *p)) {
if (!*p || !strchr(valid, *p)) {
janet_panicf("invalid conversion specifier '%%%c'", *p);
}
p++;
@@ -1946,7 +1946,7 @@ JANET_CORE_FN(os_strftime,
struct tm t_infos;
struct tm *t_info = time_to_tm(argv, argc, 1, &t_infos);
char buf[SIZETIMEFMT];
(void)strftime(buf, SIZETIMEFMT, fmt, t_info);
(void)strftime(buf, sizeof(buf), fmt, t_info);
return janet_cstringv(buf);
}
+4 -1
View File
@@ -63,7 +63,10 @@
"strftime january 2014")
(assert (= (try (os/strftime "%%%d%t") ([err] err))
"invalid conversion specifier '%t'")
"invalid conversion specifier")
"invalid conversion specifier 1")
(assert (= (try (os/strftime "%H:%M:%") ([err] err))
"invalid conversion specifier")
"invalid conversion specifier 2")
# 07db4c530
(os/setenv "TESTENV1" "v1")