[PATCH] D128607: [clang-format] NFC Fix uninitialized memory problem

sstwcw via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 26 04:02:03 PDT 2022


sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, curdeius, owenpan.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

The setLength function checks for the token kind which could be
uninitialized in the previous version.

The problem was introduced in 2e32ff106e <https://reviews.llvm.org/rG2e32ff106e740c76601004493816d0ed7c483056>.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128607

Files:
  clang/lib/Format/FormatTokenLexer.cpp


Index: clang/lib/Format/FormatTokenLexer.cpp
===================================================================
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -1128,11 +1128,12 @@
     return false;
   size_t Len = Matches[0].size();
 
-  Tok.setLength(Len);
-  Tok.setLocation(Lex->getSourceLocation(Start, Len));
   // The kind has to be an identifier so we can match it against those defined
-  // in Keywords.
+  // in Keywords. The kind has to be set before the length because the setLength
+  // function checks that the kind is not an annotation.
   Tok.setKind(tok::raw_identifier);
+  Tok.setLength(Len);
+  Tok.setLocation(Lex->getSourceLocation(Start, Len));
   Tok.setRawIdentifierData(Start);
   Lex->seek(Lex->getCurrentBufferOffset() + Len, /*IsAtStartofline=*/false);
   return true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128607.440055.patch
Type: text/x-patch
Size: 841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220626/7fa6b019/attachment.bin>


More information about the cfe-commits mailing list