[libvirt] [PATCH] 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> --- Pushing under the build-breaker rule. cfg.mk | 12 +++++++++--- src/util/virutil.c | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/cfg.mk b/cfg.mk index 13de268..791c393 100644 --- a/cfg.mk +++ b/cfg.mk @@ -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:]_]* ?\(.*[,;]$' \ diff --git a/src/util/virutil.c b/src/util/virutil.c index 3de72ea..34f5998 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -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; } } -- 1.8.3.1

On Wed, Aug 07, 2013 at 04:53:30PM -0600, Eric Blake wrote:
Commit 3d0e3c1 reintroduced a problem previously squelched in commit 7e5aa78. Add a syntax check this time around.
Didn't notice we want to avoid this sorry.
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> ---
Pushing under the build-breaker rule.
cfg.mk | 12 +++++++++--- src/util/virutil.c | 8 ++++---- 2 files changed, 13 insertions(+), 7 deletions(-)
diff --git a/cfg.mk b/cfg.mk index 13de268..791c393 100644 --- a/cfg.mk +++ b/cfg.mk @@ -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:]_]* ?\(.*[,;]$' \ diff --git a/src/util/virutil.c b/src/util/virutil.c index 3de72ea..34f5998 100644 --- a/src/util/virutil.c +++ b/src/util/virutil.c @@ -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;
And safeing a variable, nice! ACK. -_ Guido
} }
-- 1.8.3.1
-- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list

On 08/08/2013 12:41 PM, Guido Günther wrote:
On Wed, Aug 07, 2013 at 04:53:30PM -0600, Eric Blake wrote:
Commit 3d0e3c1 reintroduced a problem previously squelched in commit 7e5aa78. Add a syntax check this time around.
Didn't notice we want to avoid this sorry.
That's okay - it's my own fault for not adding a syntax-check last time it happened. Eventually, we will reach a day where we quit catering to RHEL 5's ancient gcc as our minimum version, but at least now we can detect the problem without having to resort to waiting for someone to actually test the build on RHEL 5... Maybe it's worth someone trying to set up an autobuilder on a RHEL 5 VM? (My own RHEL 5 setup is too sporadic, on only once a month or so, mainly for my own regression testing). -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

Hi Eric, On Thu, Aug 08, 2013 at 02:28:19PM -0600, Eric Blake wrote:
On 08/08/2013 12:41 PM, Guido Günther wrote:
On Wed, Aug 07, 2013 at 04:53:30PM -0600, Eric Blake wrote:
Commit 3d0e3c1 reintroduced a problem previously squelched in commit 7e5aa78. Add a syntax check this time around.
Didn't notice we want to avoid this sorry.
That's okay - it's my own fault for not adding a syntax-check last time it happened. Eventually, we will reach a day where we quit catering to RHEL 5's ancient gcc as our minimum version, but at least now we can detect the problem without having to resort to waiting for someone to actually test the build on RHEL 5...
Maybe it's worth someone trying to set up an autobuilder on a RHEL 5 VM? (My own RHEL 5 setup is too sporadic, on only once a month or so, mainly for my own regression testing).
I was hoping to add more distros to the libvirt jenkins [1] builds but am currently struggling at keeping the existent ones in shape. (Some of them are run on an irregular basis on a different machine to safe some power). I'll add RHEL5 to my todo list. Cheers, -- Guido [1] http://honk.sigxcpu.org:8001/view/libvirt/
participants (2)
-
Eric Blake
-
Guido Günther