Skip to content

Commit c8e6381

Browse files
committed
errors: introduce git_error_vset function
Right now, we only provide a `git_error_set` that has a variadic function signature. It's impossible to drive this function in a C89-compliant way from other functions that have a variadic signature, though, like for example `git_parse_error`. Implement a new `git_error_vset` function that gets a `va_list` as parameter, fixing the above problem.
1 parent e8f6341 commit c8e6381

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/errors.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,26 @@ void git_error_set_oom(void)
4949
GIT_GLOBAL->last_error = &g_git_oom_error;
5050
}
5151

52-
void git_error_set(int error_class, const char *string, ...)
52+
void git_error_set(int error_class, const char *fmt, ...)
53+
{
54+
va_list ap;
55+
56+
va_start(ap, fmt);
57+
git_error_vset(error_class, fmt, ap);
58+
va_end(ap);
59+
}
60+
61+
void git_error_vset(int error_class, const char *fmt, va_list ap)
5362
{
54-
va_list arglist;
5563
#ifdef GIT_WIN32
5664
DWORD win32_error_code = (error_class == GIT_ERROR_OS) ? GetLastError() : 0;
5765
#endif
5866
int error_code = (error_class == GIT_ERROR_OS) ? errno : 0;
5967
git_buf *buf = &GIT_GLOBAL->error_buf;
6068

6169
git_buf_clear(buf);
62-
if (string) {
63-
va_start(arglist, string);
64-
git_buf_vprintf(buf, string, arglist);
65-
va_end(arglist);
66-
70+
if (fmt) {
71+
git_buf_vprintf(buf, fmt, ap);
6772
if (error_class == GIT_ERROR_OS)
6873
git_buf_PUTS(buf, ": ");
6974
}

src/errors.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
/*
1515
* Set the error message for this thread, formatting as needed.
1616
*/
17-
18-
void git_error_set(int error_class, const char *string, ...) GIT_FORMAT_PRINTF(2, 3);
17+
void git_error_set(int error_class, const char *fmt, ...) GIT_FORMAT_PRINTF(2, 3);
18+
void git_error_vset(int error_class, const char *fmt, va_list ap);
1919

2020
/**
2121
* Set the error message for a regex failure, using the internal regex

0 commit comments

Comments
 (0)