From e5278ac66b4c0cf224f02697df451d388d36dca8 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 6 Feb 2026 16:45:56 +0100 Subject: [PATCH] Add -Werror=c99-designator and fix brace elision warnings The recent conversion of WorkerProto::Version from unsigned int to a struct exposed a latent issue: `.version = 16` was being interpreted as aggregate initialization `{.major = 16, .minor = 0}` rather than the intended wire format value. This commit adds -Werror=c99-designator to catch this class of bugs at compile time. (The bug itself was fixed in 7eb23c15f39ca413a5f3cc0d3ab630311b4709be.) For background: The hardcoded version was originally the integer 16, which in the old wire format (major << 8 | minor) meant version 0.16. However, the version checks only compared minor versions via GET_PROTOCOL_MINOR(), so this worked by accident. After the Version struct conversion, the aggregate initialization {.major = 16, .minor = 0} happened to still work because 16 > 1 in lexicographic comparison against {1, 16}. The correct version is {1, 16} because: - The worker protocol uses major version 1 (all checks are {1, x}) - Version 1.16 is when ultimate/sigs/ca fields were added - This matches the serialization check `>= {1, 16}` --- nix-meson-build-support/common/meson.build | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nix-meson-build-support/common/meson.build b/nix-meson-build-support/common/meson.build index 5fcf557e7..4a935f26e 100644 --- a/nix-meson-build-support/common/meson.build +++ b/nix-meson-build-support/common/meson.build @@ -40,6 +40,11 @@ do_pch = cxx.get_id() == 'clang' # instantiations in libutil and libstore. if cxx.get_id() == 'clang' add_project_arguments('-fpch-instantiate-templates', language : 'cpp') + # Catch brace elision bugs: when WorkerProto::Version changed from `unsigned int` + # to `struct { unsigned int major; uint8_t minor; }`, `.version = 16` silently + # became `.version = {16, 0}` instead of failing, breaking protocol compatibility + # in a subtle way + add_project_arguments('-Werror=c99-designator', language : 'cpp') endif # Detect if we're using libstdc++ (GCC's standard library)