Skip to content

Fix -Werror=implicit-fallthrough build failure in crafting.c - #201

Merged
p2r3 merged 1 commit into
p2r3:mainfrom
kovalancik06-max:fix/crafting-implicit-fallthrough
Aug 22, 2026
Merged

Fix -Werror=implicit-fallthrough build failure in crafting.c#201
p2r3 merged 1 commit into
p2r3:mainfrom
kovalancik06-max:fix/crafting-implicit-fallthrough

Conversation

@kovalancik06-max

Copy link
Copy Markdown
Contributor

Summary

  • Fixes Bug report: statement may fall through #194 — ESP-IDF/PlatformIO builds fail with -Werror=implicit-fallthrough on two spots in getCraftingOutput() in src/crafting.c.
  • Both fallthroughs are intentional (slab-recipe case group falls into the shovel/sword case group, and the axe-recipe break-guard falls into the helmet case group, so shared items like oak_planks/cobblestone get checked against both recipe sets). The fix annotates them with __attribute__((fallthrough)); instead of adding a break;, since a bare break (as suggested in the issue thread) would silently remove the shovel/sword/helmet recipes for wood, stone, and leather items.
  • __attribute__((fallthrough)) is a GCC/Clang extension independent of the C standard version, so it works under this project's C89-compatibility goal (per the discussion in Convert all source code to C89 #81 about not using C23's [[fallthrough]]).

Test plan

  • Reproduced the exact reported errors (error: unannotated fall-through between switch labels at both call sites) by compiling the pre-fix crafting.c with -Wimplicit-fallthrough -Werror.
  • Confirmed the patched file compiles cleanly with the same flags against the project's real headers (stubbed only the registries.h enum, which is normally generated from a vanilla server jar).
  • Diff is 2 lines, no behavior change on the taken branches — only silences the fallthrough diagnostic on the paths that already fell through.

Two switch blocks in getCraftingOutput() intentionally fall through
between case groups (slab recipes into shovel/sword recipes, and the
axe recipe guard into helmet recipes) so that shared items like
oak_planks/cobblestone are checked against both recipe sets. GCC's
-Wimplicit-fallthrough (enabled by default in ESP-IDF/PlatformIO
builds) flags these as errors since they aren't annotated, breaking
the ESP32 build as reported in p2r3#194.

Annotate both intentional fallthroughs with __attribute__((fallthrough)),
which is supported by GCC/Clang independent of the C standard version
(the project targets C89 compatibility, so C23's [[fallthrough]] isn't
an option, per the prior discussion in p2r3#81).
@p2r3
p2r3 merged commit 02733be into p2r3:main Aug 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug report: statement may fall through

2 participants