Skip to content

Commit 27b8b31

Browse files
committed
parse: remove use of variadic macros which are not C89 compliant
The macro `git_parse_error` is implemented in a variadic way so that it's possible to pass printf-style parameters. Unfortunately, variadic macros are not defined by C89 and thus we cannot use that functionality. But as we have implemented `git_error_vset` in the previous commit, we can now just use that instead. Convert `git_parse_error` to a variadic function and use `git_error_vset` to fix the compliance violation. While at it, move the function to "patch_parse.c".
1 parent c8e6381 commit 27b8b31

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/parse.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ typedef struct {
2828
int git_parse_ctx_init(git_parse_ctx *ctx, const char *content, size_t content_len);
2929
void git_parse_ctx_clear(git_parse_ctx *ctx);
3030

31-
#define git_parse_err(...) \
32-
( git_error_set(GIT_ERROR_PATCH, __VA_ARGS__), -1 )
33-
3431
#define git_parse_ctx_contains_s(ctx, str) \
3532
git_parse_ctx_contains(ctx, str, sizeof(str) - 1)
3633

src/patch_parse.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ typedef struct {
3333
char *old_prefix, *new_prefix;
3434
} git_patch_parsed;
3535

36+
static int git_parse_err(const char *fmt, ...) GIT_FORMAT_PRINTF(1, 2);
37+
static int git_parse_err(const char *fmt, ...)
38+
{
39+
va_list ap;
40+
41+
va_start(ap, fmt);
42+
git_error_vset(GIT_ERROR_PATCH, fmt, ap);
43+
va_end(ap);
44+
45+
return -1;
46+
}
47+
3648
static size_t header_path_len(git_patch_parse_ctx *ctx)
3749
{
3850
bool inquote = 0;

0 commit comments

Comments
 (0)