diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-05-17 22:09:56 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2011-05-17 22:09:56 +0000 |
commit | 8b7252a8b3612b79adcd2d17c09bd6f1ab3dcca3 (patch) | |
tree | c169cbf616f3a298db1a6255c6a5b8a94b37c09e /clang/include/clang/Lex/LiteralSupport.h | |
parent | f15eac1110cc963cabda42759e6eb9d6f077f30a (diff) | |
download | bcm5719-llvm-8b7252a8b3612b79adcd2d17c09bd6f1ab3dcca3.tar.gz bcm5719-llvm-8b7252a8b3612b79adcd2d17c09bd6f1ab3dcca3.zip |
Fix a nasty bug where inside StringLiteralParser:
1. We would assume that the length of the string literal token was at least 2
2. We would allocate a buffer with size length-2
And when the stars aligned (one of which would be an invalid source location due to stale PCH)
The length would be 0 and we would try to allocate a 4GB buffer.
Add checks for this corner case and a bunch of asserts.
(We really really should have had an assert for 1.).
Note that there's no test case since I couldn't get one (it was major PITA to reproduce),
maybe later.
llvm-svn: 131492
Diffstat (limited to 'clang/include/clang/Lex/LiteralSupport.h')
-rw-r--r-- | clang/include/clang/Lex/LiteralSupport.h | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/clang/include/clang/Lex/LiteralSupport.h b/clang/include/clang/Lex/LiteralSupport.h index dcaf4457cfa..ec3d9c58d67 100644 --- a/clang/include/clang/Lex/LiteralSupport.h +++ b/clang/include/clang/Lex/LiteralSupport.h @@ -156,7 +156,9 @@ public: StringLiteralParser(const Token *StringToks, unsigned NumStringToks, const SourceManager &sm, const LangOptions &features, const TargetInfo &target, Diagnostic *diags = 0) - : SM(sm), Features(features), Target(target), Diags(diags) { + : SM(sm), Features(features), Target(target), Diags(diags), + MaxTokenLength(0), SizeBound(0), wchar_tByteWidth(0), + ResultPtr(ResultBuf.data()), hadError(false), AnyWide(false), Pascal(false) { init(StringToks, NumStringToks); } @@ -165,8 +167,8 @@ public: bool AnyWide; bool Pascal; - const char *GetString() { return &ResultBuf[0]; } - unsigned GetStringLength() const { return ResultPtr-&ResultBuf[0]; } + const char *GetString() { return ResultBuf.data(); } + unsigned GetStringLength() const { return ResultPtr-ResultBuf.data(); } unsigned GetNumStringChars() const { if (AnyWide) |