]> granicus.if.org Git - llvm/commitdiff
Make BitcodeReader::parseIdentificationBlock() robust to EOF
authorMehdi Amini <mehdi.amini@apple.com>
Wed, 9 Nov 2016 21:26:49 +0000 (21:26 +0000)
committerMehdi Amini <mehdi.amini@apple.com>
Wed, 9 Nov 2016 21:26:49 +0000 (21:26 +0000)
This method is particular: it iterates at the top-level and does
not have an enclosing block.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286394 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Bitcode/Reader/BitcodeReader.cpp

index 57b03e80fa6c5422595ef834ef324dea1ab4767c..23876ffcb99712e6e5701927ca6a2db83c7454cb 100644 (file)
@@ -4347,6 +4347,12 @@ Expected<std::string> BitcodeReader::parseIdentificationBlock() {
   // We expect a number of well-defined blocks, though we don't necessarily
   // need to understand them all.
   while (true) {
+    // This loop iterates at the top-level: since there is no enclosing block
+    // we need to make sure we aren't at the end of the stream before calling
+    // advance, otherwise we'll get an error.
+    if (Stream.AtEndOfStream())
+      return Error::success();
+
     BitstreamEntry Entry = Stream.advance();
     switch (Entry.Kind) {
     case BitstreamEntry::Error: