Skip to content

Commit 21efa49

Browse files
dschoGit for Windows Build Agent
authored andcommitted
mingw: avoid the comma operator
The pattern `return errno = ..., -1;` is observed several times in `compat/mingw.c`. It has served us well over the years, but now clang starts complaining: compat/mingw.c:723:24: error: possible misuse of comma operator here [-Werror,-Wcomma] 723 | return errno = ENOSYS, -1; | ^ See for example this failing workflow run: https://github.com/git-for-windows/git-sdk-arm64/actions/runs/15457893907/job/43513458823#step:8:201 Let's appease clang (and also reduce the use of the no longer common comma operator). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 61a6132 commit 21efa49

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

compat/mingw.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,10 @@ static int mingw_open_append(wchar_t const *wfilename, int oflags, ...)
491491
DWORD create = (oflags & O_CREAT) ? OPEN_ALWAYS : OPEN_EXISTING;
492492

493493
/* only these flags are supported */
494-
if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND))
495-
return errno = ENOSYS, -1;
494+
if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND)) {
495+
errno = ENOSYS;
496+
return -1;
497+
}
496498

497499
/*
498500
* FILE_SHARE_WRITE is required to permit child processes
@@ -2450,12 +2452,14 @@ static int start_timer_thread(void)
24502452
timer_event = CreateEvent(NULL, FALSE, FALSE, NULL);
24512453
if (timer_event) {
24522454
timer_thread = (HANDLE) _beginthreadex(NULL, 0, ticktack, NULL, 0, NULL);
2453-
if (!timer_thread )
2454-
return errno = ENOMEM,
2455-
error("cannot start timer thread");
2456-
} else
2457-
return errno = ENOMEM,
2458-
error("cannot allocate resources for timer");
2455+
if (!timer_thread ) {
2456+
errno = ENOMEM;
2457+
return error("cannot start timer thread");
2458+
}
2459+
} else {
2460+
errno = ENOMEM;
2461+
return error("cannot allocate resources for timer");
2462+
}
24592463
return 0;
24602464
}
24612465

@@ -2488,13 +2492,15 @@ int setitimer(int type UNUSED, struct itimerval *in, struct itimerval *out)
24882492
static const struct timeval zero;
24892493
static int atexit_done;
24902494

2491-
if (out)
2492-
return errno = EINVAL,
2493-
error("setitimer param 3 != NULL not implemented");
2495+
if (out) {
2496+
errno = EINVAL;
2497+
return error("setitimer param 3 != NULL not implemented");
2498+
}
24942499
if (!is_timeval_eq(&in->it_interval, &zero) &&
2495-
!is_timeval_eq(&in->it_interval, &in->it_value))
2496-
return errno = EINVAL,
2497-
error("setitimer: it_interval must be zero or eq it_value");
2500+
!is_timeval_eq(&in->it_interval, &in->it_value)) {
2501+
errno = EINVAL;
2502+
return error("setitimer: it_interval must be zero or eq it_value");
2503+
}
24982504

24992505
if (timer_thread)
25002506
stop_timer_thread();
@@ -2516,12 +2522,14 @@ int sigaction(int sig, struct sigaction *in, struct sigaction *out)
25162522
{
25172523
if (sig == SIGCHLD)
25182524
return -1;
2519-
else if (sig != SIGALRM)
2520-
return errno = EINVAL,
2521-
error("sigaction only implemented for SIGALRM");
2522-
if (out)
2523-
return errno = EINVAL,
2524-
error("sigaction: param 3 != NULL not implemented");
2525+
else if (sig != SIGALRM) {
2526+
errno = EINVAL;
2527+
return error("sigaction only implemented for SIGALRM");
2528+
}
2529+
if (out) {
2530+
errno = EINVAL;
2531+
return error("sigaction: param 3 != NULL not implemented");
2532+
}
25252533

25262534
timer_fn = in->sa_handler;
25272535
return 0;

0 commit comments

Comments
 (0)