Skip to content

Fix all implicit case fallthrough (#287)#294

Merged
spe-ciellt merged 1 commit intogerbv:developfrom
SourceParts:fix/case-fallthrough
Feb 28, 2026
Merged

Fix all implicit case fallthrough (#287)#294
spe-ciellt merged 1 commit intogerbv:developfrom
SourceParts:fix/case-fallthrough

Conversation

@rampageservices
Copy link
Copy Markdown
Contributor

Summary

  • Enable -Wimplicit-fallthrough in CMakeLists.txt compiler flags
  • Annotate all intentional case fallthroughs with C23 [[fallthrough]]; attribute

Changes

File Location Fallthrough
src/amacro.c case '0':case '1': Comment is conditionally consumed, otherwise falls through to digit parsing
src/callbacks.c SAVE_FILE_RS274XMSAVE_FILE_DRILL Merged visible layers export shares drill export path
src/callbacks.c LAYER_SELECTEDdefault Resolves selected index then falls to default toggle logic
src/csv.c (×2) ST_STARTST_COLLECT State-machine transition (char and wchar_t variants)
src/drill.c case 'R':case 'S': Repeat-hole command falls through to spindle speed handler
src/main.c case 'w':case 'W': Lowercase sets pixel flag then shares window-size parsing

Test plan

  • Clean build with zero -Wimplicit-fallthrough warnings
  • 94/104 regression tests pass (same 10 pre-existing rendering mismatches)
  • Functional test: test-amacro-hex-expression.gbx exports correctly
  • Functional test: test-gerber-x2-attributes.gbx exports correctly

Closes #287

@spe-ciellt spe-ciellt added fix Solution for a potential problem or omission. and removed fix Solution for a potential problem or omission. labels Feb 28, 2026
Copy link
Copy Markdown
Contributor

@spe-ciellt spe-ciellt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One old bug found, but was fixed in the wrong way.

@spe-ciellt
Copy link
Copy Markdown
Contributor

spe-ciellt commented Feb 28, 2026

Hard blocker — drill.c case 'R'case 'S'

After processing a repeat-hole R command in the body section, the code falls through into case 'S' (spindle speed), which logs a spurious note and calls eat_line(fd) — consuming the next line from the drill file. That next line is typically a coordinate, tool change, or M30 end-of-file command, which gets silently discarded.

case 'R':
    if (state->curr_section == DRILL_HEADER) {
        // log error
    } else {
        // parse repeat count and step values
        // emit rcnt drill holes
    }
    // [[fallthrough]]; <-- PR annotates this as intentional
case 'S':
    gerbv_stats_printf(..., _("Ignoring setting spindle speed..."));
    eat_line(fd);
    break;

The existing golden-image test passes because it was generated against the same buggy code. The correct fix is a break; before case 'S':, not a [[fallthrough]];.


Likely bug — callbacks.c RS274XM → DRILL

On the success path for CALLBACKS_SAVE_FILE_RS274XM, the code falls through into the CALLBACKS_SAVE_FILE_DRILL block which overwrites windowTitle (leaking the RS-274X string) with a drill-file dialog title and sets the file extension to .drl. An RS-274X merge export should not be presenting a drill-file dialog. This looks like a missing break; that has always been there, with the PR locking it in as intentional.


Correct annotations (6 of 8)

Location Assessment
amacro.ccase '0'case '1' Correct — '0' mid-expression is a digit
callbacks.cLAYER_SELECTEDdefault Correct — replaces /* No break */ which didn't match GCC's regex
csv.c (×2) — ST_STARTST_COLLECT Correct — standard state machine optimization
main.ccase 'w'case 'W' Correct — intentional shared getopt handling

The three existing /* fall through */ comments in scheme.c are correctly left untouched — GCC level 3 already accepts them.

When you fixed it, amend it into current commit and push it --force--with-lease.

)

Enable -Wimplicit-fallthrough and add [[fallthrough]] annotations
to intentional case fallthroughs in amacro.c, callbacks.c, csv.c,
and main.c.

Fix two bugs exposed by the review:
- drill.c case 'R' was falling through to case 'S', causing
  eat_line() to consume the next drill command after repeat-hole
- callbacks.c SAVE_FILE_RS274XM was falling through to
  SAVE_FILE_DRILL, presenting a drill dialog for RS-274X export
@rampageservices
Copy link
Copy Markdown
Contributor Author

Fixed both — drill.c case 'R' and callbacks.c RS274XM now have break; instead of [[fallthrough]];. Force-pushed the amended commit.

@spe-ciellt spe-ciellt merged commit ebcbc1f into gerbv:develop Feb 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Solution for a potential problem or omission.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix all case fallthrough

2 participants