diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp index f5cb379c5a4b..327df6078fef 100644 --- a/lld/COFF/Driver.cpp +++ b/lld/COFF/Driver.cpp @@ -1258,7 +1258,7 @@ static void findKeepUniqueSections(COFFLinkerContext &ctx) { const uint8_t *cur = contents.begin(); while (cur != contents.end()) { unsigned size; - const char *err; + const char *err = nullptr; uint64_t symIndex = decodeULEB128(cur, &size, contents.end(), &err); if (err) fatal(toString(obj) + ": could not decode addrsig section: " + err); diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp index 6290880c43d3..6bef09eeca01 100644 --- a/lld/ELF/Driver.cpp +++ b/lld/ELF/Driver.cpp @@ -2296,7 +2296,7 @@ static void findKeepUniqueSections(opt::InputArgList &args) { const uint8_t *cur = contents.begin(); while (cur != contents.end()) { unsigned size; - const char *err; + const char *err = nullptr; uint64_t symIndex = decodeULEB128(cur, &size, contents.end(), &err); if (err) fatal(toString(f) + ": could not decode addrsig section: " + err); diff --git a/llvm/include/llvm/Support/LEB128.h b/llvm/include/llvm/Support/LEB128.h index a5d367279aef..7ec19fee5d8b 100644 --- a/llvm/include/llvm/Support/LEB128.h +++ b/llvm/include/llvm/Support/LEB128.h @@ -125,14 +125,15 @@ inline unsigned encodeULEB128(uint64_t Value, uint8_t *p, } /// Utility function to decode a ULEB128 value. +/// +/// If \p error is non-null, it will point to a static error message, +/// if an error occured. It will not be modified on success. inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = nullptr, const uint8_t *end = nullptr, const char **error = nullptr) { const uint8_t *orig_p = p; uint64_t Value = 0; unsigned Shift = 0; - if (error) - *error = nullptr; do { if (p == end) { if (error) @@ -158,6 +159,9 @@ inline uint64_t decodeULEB128(const uint8_t *p, unsigned *n = nullptr, } /// Utility function to decode a SLEB128 value. +/// +/// If \p error is non-null, it will point to a static error message, +/// if an error occured. It will not be modified on success. inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr, const uint8_t *end = nullptr, const char **error = nullptr) { @@ -165,8 +169,6 @@ inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr, int64_t Value = 0; unsigned Shift = 0; uint8_t Byte; - if (error) - *error = nullptr; do { if (p == end) { if (error) diff --git a/llvm/lib/Object/MachOObjectFile.cpp b/llvm/lib/Object/MachOObjectFile.cpp index aa57de16ed18..5e6c6ea79427 100644 --- a/llvm/lib/Object/MachOObjectFile.cpp +++ b/llvm/lib/Object/MachOObjectFile.cpp @@ -2996,7 +2996,7 @@ void ExportEntry::pushNode(uint64_t offset) { ErrorAsOutParameter ErrAsOutParam(E); const uint8_t *Ptr = Trie.begin() + offset; NodeState State(Ptr); - const char *error; + const char *error = nullptr; uint64_t ExportInfoSize = readULEB128(State.Current, &error); if (error) { *E = malformedError("export info size " + Twine(error) + @@ -3131,7 +3131,7 @@ void ExportEntry::pushNode(uint64_t offset) { void ExportEntry::pushDownUntilBottom() { ErrorAsOutParameter ErrAsOutParam(E); - const char *error; + const char *error = nullptr; while (Stack.back().NextChildIndex < Stack.back().ChildCount) { NodeState &Top = Stack.back(); CumulativeString.resize(Top.ParentStringLength); diff --git a/llvm/lib/Support/DataExtractor.cpp b/llvm/lib/Support/DataExtractor.cpp index 59a44f4071b5..eac3c32cfd3b 100644 --- a/llvm/lib/Support/DataExtractor.cpp +++ b/llvm/lib/Support/DataExtractor.cpp @@ -202,7 +202,7 @@ static T getLEB128(StringRef Data, uint64_t *OffsetPtr, Error *Err, if (isError(Err)) return T(); - const char *error; + const char *error = nullptr; unsigned bytes_read; T result = Decoder(Bytes.data() + *OffsetPtr, &bytes_read, Bytes.end(), &error); diff --git a/llvm/tools/llvm-readobj/COFFDumper.cpp b/llvm/tools/llvm-readobj/COFFDumper.cpp index 9c24b0b8db35..3ad40dc35510 100644 --- a/llvm/tools/llvm-readobj/COFFDumper.cpp +++ b/llvm/tools/llvm-readobj/COFFDumper.cpp @@ -2126,7 +2126,7 @@ void COFFDumper::printAddrsig() { const uint8_t *End = AddrsigContents.bytes_end(); while (Cur != End) { unsigned Size; - const char *Err; + const char *Err = nullptr; uint64_t SymIndex = decodeULEB128(Cur, &Size, End, &Err); if (Err) reportError(createError(Err), Obj->getFileName()); diff --git a/llvm/tools/llvm-readobj/ELFDumper.cpp b/llvm/tools/llvm-readobj/ELFDumper.cpp index ab26f1369407..d6d0ea35044a 100644 --- a/llvm/tools/llvm-readobj/ELFDumper.cpp +++ b/llvm/tools/llvm-readobj/ELFDumper.cpp @@ -5004,7 +5004,7 @@ static Expected> toULEB128Array(ArrayRef Data) { const uint8_t *End = Data.end(); while (Cur != End) { unsigned Size; - const char *Err; + const char *Err = nullptr; Ret.push_back(decodeULEB128(Cur, &Size, End, &Err)); if (Err) return createError(Err);