From 8f559ef8201df637706247d7e0394ade63f9a026 Mon Sep 17 00:00:00 2001 From: Ted Kremenek Date: Mon, 17 Dec 2007 22:25:12 +0000 Subject: [PATCH] Modified Deserializer::ReadCStr to allow C-strings to be read into a std::vector starting from any index in the vector. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45129 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Bitcode/Deserialize.h | 2 +- lib/Bitcode/Reader/Deserialize.cpp | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/include/llvm/Bitcode/Deserialize.h b/include/llvm/Bitcode/Deserialize.h index 430100ee286..dc1cdc0898d 100644 --- a/include/llvm/Bitcode/Deserialize.h +++ b/include/llvm/Bitcode/Deserialize.h @@ -156,7 +156,7 @@ public: } char* ReadCStr(char* cstr = NULL, unsigned MaxLen=0, bool isNullTerm=true); - void ReadCStr(std::vector& buff, bool isNullTerm=false); + void ReadCStr(std::vector& buff, bool isNullTerm=false, unsigned Idx=0); template inline T* ReadOwnedPtr(bool AutoRegister = true) { diff --git a/lib/Bitcode/Reader/Deserialize.cpp b/lib/Bitcode/Reader/Deserialize.cpp index cb32f7d5efe..8e0b62c5095 100644 --- a/lib/Bitcode/Reader/Deserialize.cpp +++ b/lib/Bitcode/Reader/Deserialize.cpp @@ -329,11 +329,18 @@ char* Deserializer::ReadCStr(char* cstr, unsigned MaxLen, bool isNullTerm) { return cstr; } -void Deserializer::ReadCStr(std::vector& buff, bool isNullTerm) { +void Deserializer::ReadCStr(std::vector& buff, bool isNullTerm, + unsigned Idx) { + unsigned len = ReadInt(); - buff.clear(); - buff.reserve(len); + // If Idx is beyond the current before size, reduce Idx to refer to the + // element after the last element. + if (Idx > buff.size()) + Idx = buff.size(); + + buff.reserve(len+Idx); + buff.resize(Idx); for (unsigned i = 0; i < len; ++i) buff.push_back((char) ReadInt());