maint: avoid C99 loop declaration

Commit 3d0e3c1 reintroduced a problem previously squelched in
commit 7e5aa78.  Add a syntax check this time around.

util/virutil.c: In function 'virGetGroupList':
util/virutil.c:1015: error: 'for' loop initial declaration used outside C99 mode

* cfg.mk (sc_prohibit_loop_var_decl): New rule.
* src/util/virutil.c (virGetGroupList): Fix offender.

Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
Eric Blake 2013-08-07 16:44:58 -06:00
parent ff38690be9
commit ed7e7c7d10
2 changed files with 13 additions and 7 deletions

12
cfg.mk
View File

@ -546,15 +546,21 @@ sc_avoid_attribute_unused_in_header:
$(_sc_search_regexp)
sc_prohibit_int_ijk:
@prohibit='\<(int|unsigned) ([^(]* )*(i|j|k)(\s|,|;)' \
@prohibit='\<(int|unsigned) ([^(]* )*(i|j|k)(\s|,|;)' \
halt='use size_t, not int/unsigned int for loop vars i, j, k' \
$(_sc_search_regexp)
sc_prohibit_loop_iijjkk:
@prohibit='\<(int|unsigned) ([^=]+ )*(ii|jj|kk)(\s|,|;)' \
halt='use i, j, k for loop iterators, not ii, jj, kk' \
@prohibit='\<(int|unsigned) ([^=]+ )*(ii|jj|kk)(\s|,|;)' \
halt='use i, j, k for loop iterators, not ii, jj, kk' \
$(_sc_search_regexp)
# RHEL 5 gcc can't grok "for (int i..."
sc_prohibit_loop_var_decl:
@prohibit='\<for *\(\w+[ *]+\w+' \
in_vc_files='\.[ch]$$' \
halt='declare loop iterators outside the for statement' \
$(_sc_search_regexp)
# Many of the function names below came from this filter:
# git grep -B2 '\<_('|grep -E '\.c- *[[:alpha:]_][[:alnum:]_]* ?\(.*[,;]$' \

View File

@ -1010,18 +1010,18 @@ virGetGroupList(uid_t uid, gid_t gid, gid_t **list)
}
if (gid != (gid_t)-1) {
size_t n = ret;
size_t i;
for (size_t i = 0; i < ret; i++) {
for (i = 0; i < ret; i++) {
if ((*list)[i] == gid)
goto cleanup;
}
if (VIR_APPEND_ELEMENT(*list, n, gid) < 0) {
if (VIR_APPEND_ELEMENT(*list, i, gid) < 0) {
ret = -1;
VIR_FREE(*list);
goto cleanup;
} else {
ret = n;
ret = i;
}
}