Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions src/patch_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,26 +458,6 @@ static int parse_header_git(
return error;
}

static int parse_number(git_off_t *out, git_patch_parse_ctx *ctx)
{
const char *end;
int64_t num;

if (!git__isdigit(ctx->parse_ctx.line[0]))
return -1;

if (git__strntol64(&num, ctx->parse_ctx.line, ctx->parse_ctx.line_len, &end, 10) < 0)
return -1;

if (num < 0)
return -1;

*out = num;
git_parse_advance_chars(&ctx->parse_ctx, (end - ctx->parse_ctx.line));

return 0;
}

static int parse_int(int *out, git_patch_parse_ctx *ctx)
{
git_off_t num;
Expand Down
10 changes: 8 additions & 2 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,15 @@ int git__strntol64(int64_t *result, const char *nptr, size_t nptr_len, const cha
/*
* Sign
*/
if (*p == '-' || *p == '+')
if (*p++ == '-')
if (*p == '-' || *p == '+') {
if (*p == '-')
neg = 1;
p++;
nptr_len--;
}

if (!nptr_len)
goto Return;

/*
* Automatically detect the base if none was given to us.
Expand Down
10 changes: 10 additions & 0 deletions tests/core/strtol.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ void test_core_strtol__buffer_length_with_leading_ws_truncates(void)
cl_assert_equal_i(i64, 1);
}

void test_core_strtol__buffer_length_with_leading_sign_truncates(void)
{
int64_t i64;

cl_git_fail(git__strntol64(&i64, "-1", 1, NULL, 10));

cl_git_pass(git__strntol64(&i64, "-11", 2, NULL, 10));
cl_assert_equal_i(i64, -1);
}

void test_core_strtol__error_message_cuts_off(void)
{
assert_l32_fails("2147483657foobar", 10);
Expand Down