Skip to content

Commit cca45ce

Browse files
committed
mingw: avoid the comma operator (#5660)
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).
2 parents a0c3877 + 762bcee commit cca45ce

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

495495
/* only these flags are supported */
496-
if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND))
497-
return errno = ENOSYS, -1;
496+
if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND)) {
497+
errno = ENOSYS;
498+
return -1;
499+
}
498500

499501
/*
500502
* FILE_SHARE_WRITE is required to permit child processes
@@ -2777,12 +2779,14 @@ static int start_timer_thread(void)
27772779
timer_event = CreateEvent(NULL, FALSE, FALSE, NULL);
27782780
if (timer_event) {
27792781
timer_thread = (HANDLE) _beginthreadex(NULL, 0, ticktack, NULL, 0, NULL);
2780-
if (!timer_thread )
2781-
return errno = ENOMEM,
2782-
error("cannot start timer thread");
2783-
} else
2784-
return errno = ENOMEM,
2785-
error("cannot allocate resources for timer");
2782+
if (!timer_thread ) {
2783+
errno = ENOMEM;
2784+
return error("cannot start timer thread");
2785+
}
2786+
} else {
2787+
errno = ENOMEM;
2788+
return error("cannot allocate resources for timer");
2789+
}
27862790
return 0;
27872791
}
27882792

@@ -2815,13 +2819,15 @@ int setitimer(int type UNUSED, struct itimerval *in, struct itimerval *out)
28152819
static const struct timeval zero;
28162820
static int atexit_done;
28172821

2818-
if (out)
2819-
return errno = EINVAL,
2820-
error("setitimer param 3 != NULL not implemented");
2822+
if (out) {
2823+
errno = EINVAL;
2824+
return error("setitimer param 3 != NULL not implemented");
2825+
}
28212826
if (!is_timeval_eq(&in->it_interval, &zero) &&
2822-
!is_timeval_eq(&in->it_interval, &in->it_value))
2823-
return errno = EINVAL,
2824-
error("setitimer: it_interval must be zero or eq it_value");
2827+
!is_timeval_eq(&in->it_interval, &in->it_value)) {
2828+
errno = EINVAL;
2829+
return error("setitimer: it_interval must be zero or eq it_value");
2830+
}
28252831

28262832
if (timer_thread)
28272833
stop_timer_thread();
@@ -2841,12 +2847,14 @@ int setitimer(int type UNUSED, struct itimerval *in, struct itimerval *out)
28412847

28422848
int sigaction(int sig, struct sigaction *in, struct sigaction *out)
28432849
{
2844-
if (sig != SIGALRM)
2845-
return errno = EINVAL,
2846-
error("sigaction only implemented for SIGALRM");
2847-
if (out)
2848-
return errno = EINVAL,
2849-
error("sigaction: param 3 != NULL not implemented");
2850+
if (sig != SIGALRM) {
2851+
errno = EINVAL;
2852+
return error("sigaction only implemented for SIGALRM");
2853+
}
2854+
if (out) {
2855+
errno = EINVAL;
2856+
return error("sigaction: param 3 != NULL not implemented");
2857+
}
28502858

28512859
timer_fn = in->sa_handler;
28522860
return 0;

0 commit comments

Comments
 (0)