Skip to content

Commit d39d5c7

Browse files
committed
Use strnlen in the strndup allocator
If we use `strlen` we'll go over the whole string rather than just the part that interests us, and sometimes we are given large strings. As en example, a 15MB reflog took ~5s to parse when using `strlen` and it fell within the noise of the tests when using `strnlen`.
1 parent c171a2a commit d39d5c7

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

ext/rugged/rugged_allocator.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static char *rugged_gstrndup(const char *str, size_t n, const char *file, int li
2828
size_t len;
2929
char *newstr;
3030

31-
len = strlen(str);
31+
len = strnlen(str, n);
3232
if (len < n)
3333
n = len;
3434

0 commit comments

Comments
 (0)