Skip to content

Commit 14a0c08

Browse files
tree data common OPTIMIZE use strnlen (#2346)
Using strlen() on large strings (large imported data) is extremely inefficient. The ly_time_str2time() only needs to check that the string is at least as long as a valid time value. However, the full value string can be very long (even > 10MB), and evaluating strlen() for every time value results in poor performance.
1 parent c8cd825 commit 14a0c08

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/tree_data_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1670,7 +1670,7 @@ ly_time_str2time(const char *value, time_t *time, char **fractions_s)
16701670
int64_t shift, shift_m;
16711671
time_t t;
16721672

1673-
LY_CHECK_ARG_RET(NULL, value, strlen(value) > 17, time, LY_EINVAL);
1673+
LY_CHECK_ARG_RET(NULL, value, strnlen(value, 18) > 17, time, LY_EINVAL);
16741674

16751675
tm.tm_year = atoi(&value[0]) - 1900;
16761676
tm.tm_mon = atoi(&value[5]) - 1;

0 commit comments

Comments
 (0)