[cfe-commits] [Patch] Teach format string analysis that "%zu" means size_t.

Hans Wennborg hans at chromium.org
Wed Oct 26 09:30:30 PDT 2011


On Wed, Oct 26, 2011 at 5:07 PM, Hans Wennborg <hans at chromium.org> wrote:
> Hi all,
>
> The attached patch teaches format string analysis that "%zu" means size_t.
>
> The code had it backwards, thinking size_t was signed, and using that for "%zd".
>
> Also let the analysis get the types for (u)intmax_t while we are at it.
>
> Please take a look and let me know if this is ok to land.
>
> Any ideas for the remaining FIXMEs in PrintfFormatString.cpp, i.e. how
> to get a hold of a type that's the same width as size_t, but signed
> would be appreciated. (And the same for unsigned version of ptrdiff_t,
> though I suppose that is less common.)
>
> It would also be cool if the warning could say "conversion specifies
> type 'size_t' (a.k.a. 'unsigned long')", rather than just using the
> underlying type, but that's probably for another patch.
>
> Thanks,
> Hans
>

Actually attaching the patch now...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: printf-format-string.diff
Type: text/x-patch
Size: 5018 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20111026/5ac7c0af/attachment.bin>


More information about the cfe-commits mailing list