Skip to content

Commit 7b03646

Browse files
committed
Merge branch 'js/comma-semicolon-confusion'
Code clean-up. * js/comma-semicolon-confusion: detect-compiler: detect clang even if it found CUDA clang: warn when the comma operator is used compat/regex: explicitly mark intentional use of the comma operator wildmatch: avoid using of the comma operator diff-delta: avoid using the comma operator xdiff: avoid using the comma operator unnecessarily clar: avoid using the comma operator unnecessarily kwset: avoid using the comma operator unnecessarily rebase: avoid using the comma operator unnecessarily remote-curl: avoid using the comma operator unnecessarily
2 parents a8c2077 + abd4192 commit 7b03646

File tree

12 files changed

+89
-52
lines changed

12 files changed

+89
-52
lines changed

builtin/rebase.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1843,7 +1843,7 @@ int cmd_rebase(int argc,
18431843
strbuf_addf(&msg, "%s (start): checkout %s",
18441844
options.reflog_action, options.onto_name);
18451845
ropts.oid = &options.onto->object.oid;
1846-
ropts.orig_head = &options.orig_head->object.oid,
1846+
ropts.orig_head = &options.orig_head->object.oid;
18471847
ropts.flags = RESET_HEAD_DETACH | RESET_ORIG_HEAD |
18481848
RESET_HEAD_RUN_POST_CHECKOUT_HOOK;
18491849
ropts.head_msg = msg.buf;

compat/regex/regex_internal.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,10 @@ re_node_set_merge (re_node_set *dest, const re_node_set *src)
12321232
is = src->nelem - 1, id = dest->nelem - 1; is >= 0 && id >= 0; )
12331233
{
12341234
if (dest->elems[id] == src->elems[is])
1235-
is--, id--;
1235+
{
1236+
is--;
1237+
id--;
1238+
}
12361239
else if (dest->elems[id] < src->elems[is])
12371240
dest->elems[--sbase] = src->elems[is--];
12381241
else /* if (dest->elems[id] > src->elems[is]) */

compat/regex/regexec.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ sift_states_bkref (const re_match_context_t *mctx, re_sift_context_t *sctx,
22102210
/* mctx->bkref_ents may have changed, reload the pointer. */
22112211
entry = mctx->bkref_ents + enabled_idx;
22122212
}
2213-
while (enabled_idx++, entry++->more);
2213+
while ((void)enabled_idx++, entry++->more);
22142214
}
22152215
err = REG_NOERROR;
22162216
free_return:

config.mak.dev

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ DEVELOPER_CFLAGS += -Wwrite-strings
4141
DEVELOPER_CFLAGS += -fno-common
4242
DEVELOPER_CFLAGS += -Wunreachable-code
4343

44+
ifneq ($(filter clang9,$(COMPILER_FEATURES)),)
45+
DEVELOPER_CFLAGS += -Wcomma
46+
endif
47+
4448
ifneq ($(filter clang4,$(COMPILER_FEATURES)),)
4549
DEVELOPER_CFLAGS += -Wtautological-constant-out-of-range-compare
4650
endif

detect-compiler

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ CC="$*"
99
#
1010
# FreeBSD clang version 3.4.1 (tags/RELEASE...)
1111
get_version_line() {
12-
LANG=C LC_ALL=C $CC -v 2>&1 | grep ' version '
12+
LANG=C LC_ALL=C $CC -v 2>&1 | sed -n '/ version /{p;q;}'
1313
}
1414

1515
get_family() {

diff-delta.c

+25-13
Original file line numberDiff line numberDiff line change
@@ -438,19 +438,31 @@ create_delta(const struct delta_index *index,
438438
op = out + outpos++;
439439
i = 0x80;
440440

441-
if (moff & 0x000000ff)
442-
out[outpos++] = moff >> 0, i |= 0x01;
443-
if (moff & 0x0000ff00)
444-
out[outpos++] = moff >> 8, i |= 0x02;
445-
if (moff & 0x00ff0000)
446-
out[outpos++] = moff >> 16, i |= 0x04;
447-
if (moff & 0xff000000)
448-
out[outpos++] = moff >> 24, i |= 0x08;
449-
450-
if (msize & 0x00ff)
451-
out[outpos++] = msize >> 0, i |= 0x10;
452-
if (msize & 0xff00)
453-
out[outpos++] = msize >> 8, i |= 0x20;
441+
if (moff & 0x000000ff) {
442+
out[outpos++] = moff >> 0;
443+
i |= 0x01;
444+
}
445+
if (moff & 0x0000ff00) {
446+
out[outpos++] = moff >> 8;
447+
i |= 0x02;
448+
}
449+
if (moff & 0x00ff0000) {
450+
out[outpos++] = moff >> 16;
451+
i |= 0x04;
452+
}
453+
if (moff & 0xff000000) {
454+
out[outpos++] = moff >> 24;
455+
i |= 0x08;
456+
}
457+
458+
if (msize & 0x00ff) {
459+
out[outpos++] = msize >> 0;
460+
i |= 0x10;
461+
}
462+
if (msize & 0xff00) {
463+
out[outpos++] = msize >> 8;
464+
i |= 0x20;
465+
}
454466

455467
*op = i;
456468

kwset.c

+29-25
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,13 @@ kwsincr (kwset_t kws, char const *text, size_t len)
197197
while (link && label != link->label)
198198
{
199199
links[depth] = link;
200-
if (label < link->label)
201-
dirs[depth++] = L, link = link->llink;
202-
else
203-
dirs[depth++] = R, link = link->rlink;
200+
if (label < link->label) {
201+
dirs[depth++] = L;
202+
link = link->llink;
203+
} else {
204+
dirs[depth++] = R;
205+
link = link->rlink;
206+
}
204207
}
205208

206209
/* The current character doesn't have an outgoing link at
@@ -257,14 +260,14 @@ kwsincr (kwset_t kws, char const *text, size_t len)
257260
switch (dirs[depth + 1])
258261
{
259262
case L:
260-
r = links[depth], t = r->llink, rl = t->rlink;
261-
t->rlink = r, r->llink = rl;
263+
r = links[depth]; t = r->llink; rl = t->rlink;
264+
t->rlink = r; r->llink = rl;
262265
t->balance = r->balance = 0;
263266
break;
264267
case R:
265-
r = links[depth], l = r->llink, t = l->rlink;
266-
rl = t->rlink, lr = t->llink;
267-
t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
268+
r = links[depth]; l = r->llink; t = l->rlink;
269+
rl = t->rlink; lr = t->llink;
270+
t->llink = l; l->rlink = lr; t->rlink = r; r->llink = rl;
268271
l->balance = t->balance != 1 ? 0 : -1;
269272
r->balance = t->balance != (char) -1 ? 0 : 1;
270273
t->balance = 0;
@@ -277,14 +280,14 @@ kwsincr (kwset_t kws, char const *text, size_t len)
277280
switch (dirs[depth + 1])
278281
{
279282
case R:
280-
l = links[depth], t = l->rlink, lr = t->llink;
281-
t->llink = l, l->rlink = lr;
283+
l = links[depth]; t = l->rlink; lr = t->llink;
284+
t->llink = l; l->rlink = lr;
282285
t->balance = l->balance = 0;
283286
break;
284287
case L:
285-
l = links[depth], r = l->rlink, t = r->llink;
286-
lr = t->llink, rl = t->rlink;
287-
t->llink = l, l->rlink = lr, t->rlink = r, r->llink = rl;
288+
l = links[depth]; r = l->rlink; t = r->llink;
289+
lr = t->llink; rl = t->rlink;
290+
t->llink = l; l->rlink = lr; t->rlink = r; r->llink = rl;
288291
l->balance = t->balance != 1 ? 0 : -1;
289292
r->balance = t->balance != (char) -1 ? 0 : 1;
290293
t->balance = 0;
@@ -567,22 +570,22 @@ bmexec (kwset_t kws, char const *text, size_t size)
567570
{
568571
while (tp <= ep)
569572
{
570-
d = d1[U(tp[-1])], tp += d;
571-
d = d1[U(tp[-1])], tp += d;
573+
d = d1[U(tp[-1])]; tp += d;
574+
d = d1[U(tp[-1])]; tp += d;
572575
if (d == 0)
573576
goto found;
574-
d = d1[U(tp[-1])], tp += d;
575-
d = d1[U(tp[-1])], tp += d;
576-
d = d1[U(tp[-1])], tp += d;
577+
d = d1[U(tp[-1])]; tp += d;
578+
d = d1[U(tp[-1])]; tp += d;
579+
d = d1[U(tp[-1])]; tp += d;
577580
if (d == 0)
578581
goto found;
579-
d = d1[U(tp[-1])], tp += d;
580-
d = d1[U(tp[-1])], tp += d;
581-
d = d1[U(tp[-1])], tp += d;
582+
d = d1[U(tp[-1])]; tp += d;
583+
d = d1[U(tp[-1])]; tp += d;
584+
d = d1[U(tp[-1])]; tp += d;
582585
if (d == 0)
583586
goto found;
584-
d = d1[U(tp[-1])], tp += d;
585-
d = d1[U(tp[-1])], tp += d;
587+
d = d1[U(tp[-1])]; tp += d;
588+
d = d1[U(tp[-1])]; tp += d;
586589
}
587590
break;
588591
found:
@@ -649,7 +652,8 @@ cwexec (kwset_t kws, char const *text, size_t len, struct kwsmatch *kwsmatch)
649652
mch = NULL;
650653
else
651654
{
652-
mch = text, accept = kwset->trie;
655+
mch = text;
656+
accept = kwset->trie;
653657
goto match;
654658
}
655659

meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ libgit_dependencies = [ ]
715715
# Makefile.
716716
if get_option('warning_level') in ['2','3', 'everything'] and compiler.get_argument_syntax() == 'gcc'
717717
foreach cflag : [
718+
'-Wcomma',
718719
'-Wdeclaration-after-statement',
719720
'-Wformat-security',
720721
'-Wold-style-definition',

remote-curl.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,7 @@ static int fetch_git(struct discovery *heads,
12391239
packet_buf_flush(&preamble);
12401240

12411241
memset(&rpc, 0, sizeof(rpc));
1242-
rpc.service_name = "git-upload-pack",
1242+
rpc.service_name = "git-upload-pack";
12431243
rpc.gzip_request = 1;
12441244

12451245
err = rpc_service(&rpc, heads, args.v, &preamble, &rpc_result);
@@ -1401,7 +1401,7 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs)
14011401
packet_buf_flush(&preamble);
14021402

14031403
memset(&rpc, 0, sizeof(rpc));
1404-
rpc.service_name = "git-receive-pack",
1404+
rpc.service_name = "git-receive-pack";
14051405

14061406
err = rpc_service(&rpc, heads, args.v, &preamble, &rpc_result);
14071407
if (rpc_result.len)

t/unit-tests/clar/clar/fs.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,12 @@ fs_copydir_helper(const char *source, const char *dest, int dest_mode)
376376
mkdir(dest, dest_mode);
377377

378378
cl_assert_(source_dir = opendir(source), "Could not open source dir");
379-
while ((d = (errno = 0, readdir(source_dir))) != NULL) {
379+
for (;;) {
380380
char *child;
381381

382+
errno = 0;
383+
if ((d = readdir(source_dir)) == NULL)
384+
break;
382385
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
383386
continue;
384387

@@ -479,9 +482,12 @@ fs_rmdir_helper(const char *path)
479482
struct dirent *d;
480483

481484
cl_assert_(dir = opendir(path), "Could not open dir");
482-
while ((d = (errno = 0, readdir(dir))) != NULL) {
485+
for (;;) {
483486
char *child;
484487

488+
errno = 0;
489+
if ((d = readdir(dir)) == NULL)
490+
break;
485491
if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
486492
continue;
487493

wildmatch.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
223223
p_ch = '[';
224224
if (t_ch == p_ch)
225225
matched = 1;
226-
continue;
226+
goto next;
227227
}
228228
if (CC_EQ(s,i, "alnum")) {
229229
if (ISALNUM(t_ch))
@@ -268,7 +268,10 @@ static int dowild(const uchar *p, const uchar *text, unsigned int flags)
268268
p_ch = 0; /* This makes "prev_ch" get set to 0. */
269269
} else if (t_ch == p_ch)
270270
matched = 1;
271-
} while (prev_ch = p_ch, (p_ch = *++p) != ']');
271+
next:
272+
prev_ch = p_ch;
273+
p_ch = *++p;
274+
} while (p_ch != ']');
272275
if (matched == negated ||
273276
((flags & WM_PATHNAME) && t_ch == '/'))
274277
return WM_NOMATCH;

xdiff/xdiffi.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,10 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
211211
for (d = fmax; d >= fmin; d -= 2) {
212212
i1 = XDL_MIN(kvdf[d], lim1);
213213
i2 = i1 - d;
214-
if (lim2 < i2)
215-
i1 = lim2 + d, i2 = lim2;
214+
if (lim2 < i2) {
215+
i1 = lim2 + d;
216+
i2 = lim2;
217+
}
216218
if (fbest < i1 + i2) {
217219
fbest = i1 + i2;
218220
fbest1 = i1;
@@ -223,8 +225,10 @@ static long xdl_split(unsigned long const *ha1, long off1, long lim1,
223225
for (d = bmax; d >= bmin; d -= 2) {
224226
i1 = XDL_MAX(off1, kvdb[d]);
225227
i2 = i1 - d;
226-
if (i2 < off2)
227-
i1 = off2 + d, i2 = off2;
228+
if (i2 < off2) {
229+
i1 = off2 + d;
230+
i2 = off2;
231+
}
228232
if (i1 + i2 < bbest) {
229233
bbest = i1 + i2;
230234
bbest1 = i1;

0 commit comments

Comments
 (0)