diff options
author | Ted Kremenek <kremenek@apple.com> | 2010-03-01 19:22:33 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2010-03-01 19:22:33 +0000 |
commit | d49d87719b8e272134e76601e3efc0197785aa8a (patch) | |
tree | bb9ac4fee49011589ca7d75ba7d6cd7c27543559 /lib/Analysis/PrintfFormatString.cpp | |
parent | e1e342f4a96f132d8d7e802284417bd520f9f4f8 (diff) |
Allow a '0' precision in format strings (as the man page says it is okay).
Fixes <rdar://problem/7700339>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@97482 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/PrintfFormatString.cpp')
-rw-r--r-- | lib/Analysis/PrintfFormatString.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/lib/Analysis/PrintfFormatString.cpp b/lib/Analysis/PrintfFormatString.cpp index 6d6b370b3f..46acc8a377 100644 --- a/lib/Analysis/PrintfFormatString.cpp +++ b/lib/Analysis/PrintfFormatString.cpp @@ -69,18 +69,17 @@ static OptionalAmount ParseAmount(const char *&Beg, const char *E) { UpdateOnReturn <const char*> UpdateBeg(Beg, I); unsigned accumulator = 0; + bool hasDigits = false; for ( ; I != E; ++I) { char c = *I; if (c >= '0' && c <= '9') { - // Ignore '0' on the first character. - if (c == '0' && I == Beg) - break; + hasDigits = true; accumulator += (accumulator * 10) + (c - '0'); continue; } - if (accumulator) + if (hasDigits) return OptionalAmount(OptionalAmount::Constant, accumulator, Beg); break; @@ -118,9 +117,18 @@ static OptionalAmount ParsePositionAmount(FormatStringHandler &H, return OptionalAmount(false); } + assert(Amt.getHowSpecified() == OptionalAmount::Constant); + if (*I == '$') { + // Special case: '*0$', since this is an easy mistake. + if (Amt.getConstantAmount() == 0) { + H.HandleZeroPosition(Beg, I - Beg + 1); + return OptionalAmount(false); + } + const char *Tmp = Beg; Beg = ++I; + return OptionalAmount(OptionalAmount::Arg, Amt.getConstantAmount() - 1, Tmp); } @@ -182,6 +190,12 @@ static bool ParseArgPosition(FormatStringHandler &H, } if (Amt.getHowSpecified() == OptionalAmount::Constant && *(I++) == '$') { + // Special case: '%0$', since this is an easy mistake. + if (Amt.getConstantAmount() == 0) { + H.HandleZeroPosition(Start, I - Start); + return true; + } + FS.setArgIndex(Amt.getConstantAmount() - 1); FS.setUsesPositionalArg(); // Update the caller's pointer if we decided to consume @@ -190,12 +204,6 @@ static bool ParseArgPosition(FormatStringHandler &H, return false; } - // Special case: '%0$', since this is an easy mistake. - if (*I == '0' && (I+1) != E && *(I+1) == '$') { - H.HandleZeroPosition(Start, I - Start + 2); - return true; - } - return false; } |