Skip to content

Commit 30212b7

Browse files
johnstiles-googleSkia Commit-Bot
authored andcommitted
Fix implicit fallthroughs throughout Skia.
This CL is not fully comprehensive; for instance, it does not contain fixes for backends that don't compile on Mac. But it does resolve the vast majority of cases that trigger -Wimplicit-fallthrough. A few minor bugs were found and fixed, but none that were likely to affect normal operation. Change-Id: I43487602b0d56200ce8b42702e04f66390d82f60 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/295916 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: John Stiles <johnstiles@google.com>
1 parent 77968f0 commit 30212b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+303
-204
lines changed

dm/DMSrcSink.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ Result CodecSrc::draw(SkCanvas* canvas) const {
512512
return Result::Skip(
513513
"Cannot decode frame %i to 565 (%s).", i, fPath.c_str());
514514
}
515-
// Fall through.
515+
[[fallthrough]];
516516
default:
517517
return Result::Fatal(
518518
"Couldn't getPixels for frame %i in %s.", i, fPath.c_str());

fuzz/FuzzMain.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ static void fuzz_img(sk_sp<SkData> bytes, uint8_t scale, uint8_t mode) {
464464
SkDebugf("Incompatible colortype conversion\n");
465465
// Crash to allow afl-fuzz to know this was a bug.
466466
raise(SIGSEGV);
467+
break;
467468
default:
468469
SkDebugf("[terminated] Couldn't getPixels.\n");
469470
return;
@@ -594,15 +595,15 @@ static void fuzz_img(sk_sp<SkData> bytes, uint8_t scale, uint8_t mode) {
594595
return;
595596
}
596597
// If the first subset succeeded, a later one should not fail.
597-
// fall through to failure
598+
[[fallthrough]];
598599
case SkCodec::kUnimplemented:
599600
if (0 == (x|y)) {
600601
// First subset is okay to return unimplemented.
601602
SkDebugf("[terminated] subset codec not supported\n");
602603
return;
603604
}
604605
// If the first subset succeeded, why would a later one fail?
605-
// fall through to failure
606+
[[fallthrough]];
606607
default:
607608
SkDebugf("[terminated] subset codec failed to decode (%d, %d, %d, %d) "
608609
"with dimensions (%d x %d)\t error %d\n",

gm/dstreadshuffle.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class DstReadShuffle : public GM {
100100
SkFont font(ToolUtils::create_portable_typeface(), 100);
101101
font.setEmbolden(true);
102102
canvas->drawString(text, 0.f, 100.f, font, *paint);
103+
break;
103104
}
104105
default:
105106
break;

gm/xfermodes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class XfermodesGM : public skiagm::GM {
154154
canvas->saveLayer(&bounds, &p);
155155
restoreNeeded = true;
156156
p.setBlendMode(SkBlendMode::kSrcOver);
157-
// Fall through.
157+
[[fallthrough]];
158158
}
159159
case kQuarterClear_SrcType: {
160160
SkScalar halfW = SkIntToScalar(W) / 2;
@@ -175,7 +175,7 @@ class XfermodesGM : public skiagm::GM {
175175
SkScalar h = SkIntToScalar(H);
176176
SkRect r = SkRect::MakeXYWH(x, y + h / 4, w, h * 23 / 60);
177177
canvas->clipRect(r);
178-
// Fall through.
178+
[[fallthrough]];
179179
}
180180
case kRectangle_SrcType: {
181181
SkScalar w = SkIntToScalar(W);
@@ -188,10 +188,10 @@ class XfermodesGM : public skiagm::GM {
188188
}
189189
case kSmallRectangleImageWithAlpha_SrcType:
190190
m.postScale(SK_ScalarHalf, SK_ScalarHalf, x, y);
191-
// Fall through.
191+
[[fallthrough]];
192192
case kRectangleImageWithAlpha_SrcType:
193193
p.setAlpha(0x88);
194-
// Fall through.
194+
[[fallthrough]];
195195
case kRectangleImage_SrcType: {
196196
SkAutoCanvasRestore acr(canvas, true);
197197
canvas->concat(m);

modules/skparagraph/src/ParagraphImpl.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,8 +1055,12 @@ void ParagraphImpl::setState(InternalState state) {
10551055
fBidiRegions.reset();
10561056
fGraphemes16.reset();
10571057
fCodepoints.reset();
1058+
[[fallthrough]];
1059+
10581060
case kShaped:
10591061
fClusters.reset();
1062+
[[fallthrough]];
1063+
10601064
case kClusterized:
10611065
case kMarked:
10621066
case kLineBroken:
@@ -1065,12 +1069,15 @@ void ParagraphImpl::setState(InternalState state) {
10651069
this->computeEmptyMetrics();
10661070
this->resetShifts();
10671071
fLines.reset();
1072+
[[fallthrough]];
1073+
10681074
case kFormatted:
10691075
fPicture = nullptr;
1076+
[[fallthrough]];
1077+
10701078
case kDrawn:
1079+
default:
10711080
break;
1072-
default:
1073-
break;
10741081
}
10751082
}
10761083

samplecode/SampleAAGeometry.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ static void set_path_verb(int index, SkPath::Verb v, SkPath* path, SkScalar w) {
278278
switch (v) {
279279
case SkPath::kConic_Verb:
280280
weight = w;
281+
[[fallthrough]];
281282
case SkPath::kQuad_Verb:
282283
pts[2] = pts[1];
283284
pts[1].fX = (pts[0].fX + pts[2].fX) / 2;
@@ -303,6 +304,7 @@ static void set_path_verb(int index, SkPath::Verb v, SkPath* path, SkScalar w) {
303304
break;
304305
case SkPath::kConic_Verb:
305306
weight = w;
307+
[[fallthrough]];
306308
case SkPath::kQuad_Verb:
307309
break;
308310
case SkPath::kCubic_Verb: {
@@ -325,6 +327,7 @@ static void set_path_verb(int index, SkPath::Verb v, SkPath* path, SkScalar w) {
325327
break;
326328
case SkPath::kConic_Verb:
327329
weight = w;
330+
[[fallthrough]];
328331
case SkPath::kQuad_Verb: {
329332
SkDCubic dCubic;
330333
dCubic.set(pts);

samplecode/SampleAnimatedImage.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,10 @@ class SampleAnimatedImage : public Sample {
104104
switch (uni) {
105105
case kPauseKey:
106106
fRunning = !fRunning;
107-
if (fImage->isFinished()) {
108-
// fall through
109-
} else {
107+
if (!fImage->isFinished()) {
110108
return true;
111109
}
110+
[[fallthrough]];
112111
case kResetKey:
113112
fImage->reset();
114113
fCurrentTime = fLastWallTime;

src/codec/SkBmpCodec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ SkCodec::Result SkBmpCodec::ReadHeader(SkStream* stream, bool inIco,
394394
inputFormat = kRLE_BmpInputFormat;
395395
break;
396396
}
397-
// Fall through
397+
[[fallthrough]];
398398
case kPng_BmpCompressionMethod:
399399
// TODO: Decide if we intend to support this.
400400
// It is unsupported in the previous version and

src/codec/SkPngCodec.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,8 +1018,7 @@ SkCodec::Result SkPngCodec::initializeXforms(const SkImageInfo& dstInfo, const O
10181018
if (this->getEncodedInfo().bitsPerComponent() != 16) {
10191019
break;
10201020
}
1021-
1022-
// Fall through
1021+
[[fallthrough]];
10231022
case SkEncodedInfo::kRGBA_Color:
10241023
case SkEncodedInfo::kGray_Color:
10251024
skipFormatConversion = this->colorXform();

src/codec/SkWebpCodec.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ std::unique_ptr<SkCodec> SkWebpCodec::MakeFromStream(std::unique_ptr<SkStream> s
143143
// sense to guess kBGRA which is likely closer to the final
144144
// output. Otherwise, we might end up converting
145145
// BGRA->YUVA->BGRA.
146-
// Fallthrough:
146+
[[fallthrough]];
147147
case 2:
148148
// This is the lossless format (BGRA).
149149
if (hasAlpha) {

0 commit comments

Comments
 (0)