[libvirt] [PATCH 31/31] syntax-check: Add the rule to forbid whitespace before "; "

Eric Blake eblake at redhat.com
Tue May 21 15:40:59 UTC 2013


On 05/21/2013 04:01 AM, Osier Yang wrote:
> Only a few cases are allowed:
> 
> 1) The expression is empty for "for" loop, E.g.
> 
>   for (i = 0; ; i++)
> 
> 2) An empty statement
> 
>   while (write(statuswrite, &status, 1) == -1 &&
>          errno == EINTR)
>       ; /* empty */
> 
> 3) ";" is inside double-quote, I.e, as part of const string. E.g.
> 
>   vshPrint(ctl, "a ; b ; cd;\n");
> 
> The "for" loop in src/rpc/virnettlscontext.c is the special case,
> 1) applies for it, so change it together in this patch.
> ---
>  build-aux/bracket-spacing.pl | 18 ++++++++++++++++++
>  src/rpc/virnettlscontext.c   |  2 +-
>  2 files changed, 19 insertions(+), 1 deletion(-)

ACK.

> 
> diff --git a/build-aux/bracket-spacing.pl b/build-aux/bracket-spacing.pl
> index d3a916f..0d5d2ed 100755
> --- a/build-aux/bracket-spacing.pl
> +++ b/build-aux/bracket-spacing.pl
> @@ -109,6 +109,24 @@ foreach my $file (@ARGV) {
>              $ret = 1;
>              last;
>          }
> +
> +        # Forbid whitespace before ";". Things like below are allowed:
> +        #
> +        # for (i = 0; ; i++)
> +        #
> +        # while (write(statuswrite, &status, 1) == -1 &&
> +        #        errno == EINTR)
> +        #     ;
> +        #
> +        # printf("%s", "a ; b\n");
> +        while ($data =~ /[^;\s]\s+;/) {
> +            # Inside the double-quote
> +            if ($data !~ /"[^"]*\s;/) {

False negative on:
  for (str = "foo" ; *str; str++)
but I don't think we are likely to iterate over bytes of a string
literal, so I'm not too worried about it.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 621 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20130521/babe39ea/attachment-0001.sig>


More information about the libvir-list mailing list