Page MenuHomePhabricator

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

Authored by MyDeveloperDay on Sep 17 2019, 10:37 AM.

Details

Summary

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

Diff Detail

Repository
rL LLVM

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptSep 17 2019, 10:37 AM
klimek added inline comments.Sep 17 2019, 11:27 AM
clang/lib/Format/FormatTokenLexer.cpp
660 ↗(On Diff #220535)

Shouldn't that be (Style.TabWidth ? Column % Style.TabWidth)?
Otherwise can't that still crash when Column != 0 and TabWidth is 0?

MyDeveloperDay marked an inline comment as done.Sep 17 2019, 12:15 PM
MyDeveloperDay added inline comments.
clang/lib/Format/FormatTokenLexer.cpp
660 ↗(On Diff #220535)

let me add some tests...

I should have known it was more involved.

v % 0 and v / 0 are both undefined behavior

MyDeveloperDay marked an inline comment as done.Sep 17 2019, 1:48 PM
klimek accepted this revision.Sep 18 2019, 12:45 AM

LG. That makes lots of sense now :) Thanks!

This revision is now accepted and ready to land.Sep 18 2019, 12:45 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 18 2019, 11:58 AM