diff options
author | Dario Domizioli <dario.domizioli@gmail.com> | 2014-10-15 16:18:20 +0000 |
---|---|---|
committer | Dario Domizioli <dario.domizioli@gmail.com> | 2014-10-15 16:18:20 +0000 |
commit | a60f532a9132c39e4fbd4000f6c2dc20221c44a8 (patch) | |
tree | 829f54799181c4b98c63f5ab97ba001a98175da9 /clang/lib/AST/CommentCommandTraits.cpp | |
parent | d79c4fd595a24493ea0d9ec84019ef52c4cad41b (diff) | |
download | bcm5719-llvm-a60f532a9132c39e4fbd4000f6c2dc20221c44a8.tar.gz bcm5719-llvm-a60f532a9132c39e4fbd4000f6c2dc20221c44a8.zip |
Fix for PR21254 - Assertion in comment parser
The size of the ID field in CommandInfo was narrow, leading to potential
wrap-around of command IDs, causing misinterpretation later on.
The patch does the following:
- It extends the ID bitfield from 8 to 20 bits.
- It provides a DRY definition of the number of bits for the field to
avoid using literal numbers in different files.
- It introduces a new assertion that checks for the wrap-around.
- It adds the testcase from PR21254.
llvm-svn: 219802
Diffstat (limited to 'clang/lib/AST/CommentCommandTraits.cpp')
-rw-r--r-- | clang/lib/AST/CommentCommandTraits.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/clang/lib/AST/CommentCommandTraits.cpp b/clang/lib/AST/CommentCommandTraits.cpp index a7b07a40c98..7378a7c3ac0 100644 --- a/clang/lib/AST/CommentCommandTraits.cpp +++ b/clang/lib/AST/CommentCommandTraits.cpp @@ -89,6 +89,10 @@ CommandInfo *CommandTraits::createCommandInfoWithName(StringRef CommandName) { // Value-initialize (=zero-initialize in this case) a new CommandInfo. CommandInfo *Info = new (Allocator) CommandInfo(); Info->Name = Name; + // We only have a limited number of bits to encode command IDs in the + // CommandInfo structure, so the ID numbers can potentially wrap around. + assert((NextID < (1 << CommandInfo::NumCommandIDBits)) + && "Too many commands. We have limited bits for the command ID."); Info->ID = NextID++; RegisteredCommands.push_back(Info); |