[cfe-commits] Source range error on format string

Ted Kremenek kremenek at apple.com
Thu Dec 2 13:01:31 PST 2010


Thanks for spotting this.  Fixed here:

http://llvm.org/viewvc/llvm-project?view=rev&revision=120735

On Dec 2, 2010, at 7:06 AM, Paul Curtis wrote:

> Hi,
> 
> Clang currently produces quite a wide source range for this particular
> format error:
> 
>> clang -fsyntax-only foo1.c
> foo1.c(5) :  warning: invalid conversion specifier '!' [-Wformat]
>  printf("Format %d, is %! %f", 1, 2, 4.4);
>                   ~~~~~~^
> 1 warning generated.
> 
> The source range spans from the end of the last formatter to the end of the
> current one.  
> 
> In ParsePrintfSpecifier you have:
> 
>  if (k == ConversionSpecifier::InvalidSpecifier) {
>    // Assume the conversion takes one argument.
>    return !H.HandleInvalidPrintfConversionSpecifier(FS, Beg, I - Beg);
>  }
> 
> ...whereas I think what you mean is:
> 
>  if (k == ConversionSpecifier::InvalidSpecifier) {
>    // Assume the conversion takes one argument.
>    return !H.HandleInvalidPrintfConversionSpecifier(FS, Start, I - Start);
>  }
> 
> With this patch (sorry, it's so small I just can't bring myself to attach
> one) you now get:
> 
>> clang -fsyntax-only -Wall foo1.c
> foo1.c(5) :  warning: invalid conversion specifier '!' [-Wformat]
>  printf("Format %d, is %! %f", 1, 2, 4.4);
>                        ~^
> 1 warning generated.
> 
> This is more appropriate, IMO.  It certainly is when expanding source ranges
> in an IDE.
> 
> Regards,
> 
> --
> Paul Curtis, Rowley Associates Ltd   http://www.rowley.co.uk
> SolderCore arriving Winter 2010!   http://www.soldercore.com
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list