Skip to content

Commit 9984a9f

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 b4a9dc0 + 9ec5aae commit 9984a9f

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
@@ -2779,12 +2781,14 @@ static int start_timer_thread(void)
27792781
timer_event = CreateEvent(NULL, FALSE, FALSE, NULL);
27802782
if (timer_event) {
27812783
timer_thread = (HANDLE) _beginthreadex(NULL, 0, ticktack, NULL, 0, NULL);
2782-
if (!timer_thread )
2783-
return errno = ENOMEM,
2784-
error("cannot start timer thread");
2785-
} else
2786-
return errno = ENOMEM,
2787-
error("cannot allocate resources for timer");
2784+
if (!timer_thread ) {
2785+
errno = ENOMEM;
2786+
return error("cannot start timer thread");
2787+
}
2788+
} else {
2789+
errno = ENOMEM;
2790+
return error("cannot allocate resources for timer");
2791+
}
27882792
return 0;
27892793
}
27902794

@@ -2817,13 +2821,15 @@ int setitimer(int type UNUSED, struct itimerval *in, struct itimerval *out)
28172821
static const struct timeval zero;
28182822
static int atexit_done;
28192823

2820-
if (out)
2821-
return errno = EINVAL,
2822-
error("setitimer param 3 != NULL not implemented");
2824+
if (out) {
2825+
errno = EINVAL;
2826+
return error("setitimer param 3 != NULL not implemented");
2827+
}
28232828
if (!is_timeval_eq(&in->it_interval, &zero) &&
2824-
!is_timeval_eq(&in->it_interval, &in->it_value))
2825-
return errno = EINVAL,
2826-
error("setitimer: it_interval must be zero or eq it_value");
2829+
!is_timeval_eq(&in->it_interval, &in->it_value)) {
2830+
errno = EINVAL;
2831+
return error("setitimer: it_interval must be zero or eq it_value");
2832+
}
28272833

28282834
if (timer_thread)
28292835
stop_timer_thread();
@@ -2845,12 +2851,14 @@ int sigaction(int sig, struct sigaction *in, struct sigaction *out)
28452851
{
28462852
if (sig == SIGCHLD)
28472853
return -1;
2848-
else if (sig != SIGALRM)
2849-
return errno = EINVAL,
2850-
error("sigaction only implemented for SIGALRM");
2851-
if (out)
2852-
return errno = EINVAL,
2853-
error("sigaction: param 3 != NULL not implemented");
2854+
else if (sig != SIGALRM) {
2855+
errno = EINVAL;
2856+
return error("sigaction only implemented for SIGALRM");
2857+
}
2858+
if (out) {
2859+
errno = EINVAL;
2860+
return error("sigaction: param 3 != NULL not implemented");
2861+
}
28542862

28552863
timer_fn = in->sa_handler;
28562864
return 0;

0 commit comments

Comments
 (0)