Skip to content

Commit fb89f37

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 6792aa8 commit fb89f37

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

721721
/* only these flags are supported */
722-
if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND))
723-
return errno = ENOSYS, -1;
722+
if ((oflags & ~O_CREAT) != (O_WRONLY | O_APPEND)) {
723+
errno = ENOSYS;
724+
return -1;
725+
}
724726

725727
/*
726728
* FILE_SHARE_WRITE is required to permit child processes
@@ -3096,12 +3098,14 @@ static int start_timer_thread(void)
30963098
timer_event = CreateEvent(NULL, FALSE, FALSE, NULL);
30973099
if (timer_event) {
30983100
timer_thread = (HANDLE) _beginthreadex(NULL, 0, ticktack, NULL, 0, NULL);
3099-
if (!timer_thread )
3100-
return errno = ENOMEM,
3101-
error("cannot start timer thread");
3102-
} else
3103-
return errno = ENOMEM,
3104-
error("cannot allocate resources for timer");
3101+
if (!timer_thread ) {
3102+
errno = ENOMEM;
3103+
return error("cannot start timer thread");
3104+
}
3105+
} else {
3106+
errno = ENOMEM;
3107+
return error("cannot allocate resources for timer");
3108+
}
31053109
return 0;
31063110
}
31073111

@@ -3134,13 +3138,15 @@ int setitimer(int type UNUSED, struct itimerval *in, struct itimerval *out)
31343138
static const struct timeval zero;
31353139
static int atexit_done;
31363140

3137-
if (out)
3138-
return errno = EINVAL,
3139-
error("setitimer param 3 != NULL not implemented");
3141+
if (out) {
3142+
errno = EINVAL;
3143+
return error("setitimer param 3 != NULL not implemented");
3144+
}
31403145
if (!is_timeval_eq(&in->it_interval, &zero) &&
3141-
!is_timeval_eq(&in->it_interval, &in->it_value))
3142-
return errno = EINVAL,
3143-
error("setitimer: it_interval must be zero or eq it_value");
3146+
!is_timeval_eq(&in->it_interval, &in->it_value)) {
3147+
errno = EINVAL;
3148+
return error("setitimer: it_interval must be zero or eq it_value");
3149+
}
31443150

31453151
if (timer_thread)
31463152
stop_timer_thread();
@@ -3160,12 +3166,14 @@ int setitimer(int type UNUSED, struct itimerval *in, struct itimerval *out)
31603166

31613167
int sigaction(int sig, struct sigaction *in, struct sigaction *out)
31623168
{
3163-
if (sig != SIGALRM)
3164-
return errno = EINVAL,
3165-
error("sigaction only implemented for SIGALRM");
3166-
if (out)
3167-
return errno = EINVAL,
3168-
error("sigaction: param 3 != NULL not implemented");
3169+
if (sig != SIGALRM) {
3170+
errno = EINVAL;
3171+
return error("sigaction only implemented for SIGALRM");
3172+
}
3173+
if (out) {
3174+
errno = EINVAL;
3175+
return error("sigaction: param 3 != NULL not implemented");
3176+
}
31693177

31703178
timer_fn = in->sa_handler;
31713179
return 0;

0 commit comments

Comments
 (0)