Skip to content

Commit 762bcee

Browse files
committed
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 fc4c0a2 commit 762bcee

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
@@ -501,8 +501,10 @@ static int mingw_open_append(wchar_t const *wfilename, int oflags, ...)
501501
DWORD create = (oflags & O_CREAT) ? OPEN_ALWAYS : OPEN_EXISTING;
502502

503503
/* only these flags are supported */
504-
if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND))
505-
return errno = ENOSYS, -1;
504+
if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND)) {
505+
errno = ENOSYS;
506+
return -1;
507+
}
506508

507509
/*
508510
* FILE_SHARE_WRITE is required to permit child processes
@@ -2497,12 +2499,14 @@ static int start_timer_thread(void)
24972499
timer_event = CreateEvent(NULL, FALSE, FALSE, NULL);
24982500
if (timer_event) {
24992501
timer_thread = (HANDLE) _beginthreadex(NULL, 0, ticktack, NULL, 0, NULL);
2500-
if (!timer_thread )
2501-
return errno = ENOMEM,
2502-
error("cannot start timer thread");
2503-
} else
2504-
return errno = ENOMEM,
2505-
error("cannot allocate resources for timer");
2502+
if (!timer_thread ) {
2503+
errno = ENOMEM;
2504+
return error("cannot start timer thread");
2505+
}
2506+
} else {
2507+
errno = ENOMEM;
2508+
return error("cannot allocate resources for timer");
2509+
}
25062510
return 0;
25072511
}
25082512

@@ -2535,13 +2539,15 @@ int setitimer(int type UNUSED, struct itimerval *in, struct itimerval *out)
25352539
static const struct timeval zero;
25362540
static int atexit_done;
25372541

2538-
if (out)
2539-
return errno = EINVAL,
2540-
error("setitimer param 3 != NULL not implemented");
2542+
if (out) {
2543+
errno = EINVAL;
2544+
return error("setitimer param 3 != NULL not implemented");
2545+
}
25412546
if (!is_timeval_eq(&in->it_interval, &zero) &&
2542-
!is_timeval_eq(&in->it_interval, &in->it_value))
2543-
return errno = EINVAL,
2544-
error("setitimer: it_interval must be zero or eq it_value");
2547+
!is_timeval_eq(&in->it_interval, &in->it_value)) {
2548+
errno = EINVAL;
2549+
return error("setitimer: it_interval must be zero or eq it_value");
2550+
}
25452551

25462552
if (timer_thread)
25472553
stop_timer_thread();
@@ -2561,12 +2567,14 @@ int setitimer(int type UNUSED, struct itimerval *in, struct itimerval *out)
25612567

25622568
int sigaction(int sig, struct sigaction *in, struct sigaction *out)
25632569
{
2564-
if (sig != SIGALRM)
2565-
return errno = EINVAL,
2566-
error("sigaction only implemented for SIGALRM");
2567-
if (out)
2568-
return errno = EINVAL,
2569-
error("sigaction: param 3 != NULL not implemented");
2570+
if (sig != SIGALRM) {
2571+
errno = EINVAL;
2572+
return error("sigaction only implemented for SIGALRM");
2573+
}
2574+
if (out) {
2575+
errno = EINVAL;
2576+
return error("sigaction: param 3 != NULL not implemented");
2577+
}
25702578

25712579
timer_fn = in->sa_handler;
25722580
return 0;

0 commit comments

Comments
 (0)