[PATCH] D67670: [clang-format][PR41964] Fix crash with SIGFPE when TabWidth is set to 0 and line starts with tab

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 17 10:43:29 PDT 2019


MyDeveloperDay created this revision.
MyDeveloperDay added reviewers: owenpan, klimek, russellmcc, timwoj.
MyDeveloperDay added a project: clang-tools-extra.
Herald added a project: clang.

clang-format 8.0 crashes with SIGFPE (floating point exception) when formatting following file:
app.cpp:
void a() {
	//line starts with '\t'
}

$ clang-format -style='{TabWidth: 0}' app.cpp


Repository:
  rC Clang

https://reviews.llvm.org/D67670

Files:
  clang/lib/Format/FormatTokenLexer.cpp


Index: clang/lib/Format/FormatTokenLexer.cpp
===================================================================
--- clang/lib/Format/FormatTokenLexer.cpp
+++ clang/lib/Format/FormatTokenLexer.cpp
@@ -657,7 +657,7 @@
         ++Column;
         break;
       case '\t':
-        Column += Style.TabWidth - Column % Style.TabWidth;
+        Column += Style.TabWidth - (Column ? Column % Style.TabWidth : 0);
         break;
       case '\\':
         if (i + 1 == e || (Text[i + 1] != '\r' && Text[i + 1] != '\n'))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67670.220535.patch
Type: text/x-patch
Size: 514 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190917/166323e5/attachment-0001.bin>


More information about the cfe-commits mailing list