From 79401cce8bd416dc131b28b0870882f8b6bc53af Mon Sep 17 00:00:00 2001 From: Rangi42 Date: Mon, 27 Jan 2025 19:59:06 -0500 Subject: [PATCH] Add braces inside `#define` macro bodies --- include/helpers.hpp | 3 ++- include/link/main.hpp | 3 ++- src/fix/main.cpp | 6 ++++-- src/link/output.cpp | 6 ++++-- src/link/sdas_obj.cpp | 9 ++++++--- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/include/helpers.hpp b/include/helpers.hpp index e68eeadad..1fc732ccd 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -27,8 +27,9 @@ static inline void unreachable_() { // `[[gnu::assume()]]` for GCC or compatible also has insufficient support (GCC 13+ only) #define assume(x) \ do { \ - if (!(x)) \ + if (!(x)) { \ unreachable_(); \ + } \ } while (0) #endif #else diff --git a/include/link/main.hpp b/include/link/main.hpp index 6e4c69137..4634f9b35 100644 --- a/include/link/main.hpp +++ b/include/link/main.hpp @@ -32,8 +32,9 @@ extern bool disablePadding; // Helper macro for printing verbose-mode messages #define verbosePrint(...) \ do { \ - if (beVerbose) \ + if (beVerbose) { \ fprintf(stderr, __VA_ARGS__); \ + } \ } while (0) struct FileStackNode { diff --git a/src/fix/main.cpp b/src/fix/main.cpp index b8b1c4a1b..ccdcaef52 100644 --- a/src/fix/main.cpp +++ b/src/fix/main.cpp @@ -245,8 +245,9 @@ static MbcType parseMBC(char const *name) { #define tryReadSlice(expected) \ do { \ - if (!readMBCSlice(ptr, expected)) \ + if (!readMBCSlice(ptr, expected)) { \ return MBC_BAD; \ + } \ } while (0) switch (*ptr++) { @@ -1313,8 +1314,9 @@ int main(int argc, char *argv[]) { switch (*musl_optarg) { #define OVERRIDE_SPEC(cur, bad, curFlag, badFlag) \ case STR(cur)[0]: \ - if (fixSpec & badFlag) \ + if (fixSpec & badFlag) { \ fprintf(stderr, "warning: '" STR(cur) "' overriding '" STR(bad) "' in fix spec\n"); \ + } \ fixSpec = (fixSpec & ~badFlag) | curFlag; \ break #define overrideSpecs(fix, fixFlag, trash, trashFlag) \ diff --git a/src/link/output.cpp b/src/link/output.cpp index d3d33d69a..66f52389a 100644 --- a/src/link/output.cpp +++ b/src/link/output.cpp @@ -347,12 +347,14 @@ static void writeSymBank(SortedSections const &bankSections, SectionType type, u for (auto it = bankSections.zeroLenSections.begin(); \ it != bankSections.zeroLenSections.end(); \ it++) { \ - for (Section const *sect = *it; sect; sect = sect->nextu.get()) \ + for (Section const *sect = *it; sect; sect = sect->nextu.get()) { \ __VA_ARGS__ \ + } \ } \ for (auto it = bankSections.sections.begin(); it != bankSections.sections.end(); it++) { \ - for (Section const *sect = *it; sect; sect = sect->nextu.get()) \ + for (Section const *sect = *it; sect; sect = sect->nextu.get()) { \ __VA_ARGS__ \ + } \ } \ } while (0) diff --git a/src/link/sdas_obj.cpp b/src/link/sdas_obj.cpp index 36b87dad0..e0620f8e7 100644 --- a/src/link/sdas_obj.cpp +++ b/src/link/sdas_obj.cpp @@ -148,19 +148,21 @@ void sdobj_ReadFile(FileStackNode const &where, FILE *file, std::vector #define getToken(ptr, ...) \ do { \ token = strtok((ptr), delim); \ - if (!token) \ + if (!token) { \ fatal(&where, lineNo, __VA_ARGS__); \ + } \ } while (0) #define expectEol(...) \ do { \ token = strtok(nullptr, delim); \ - if (token) \ + if (token) { \ fatal(&where, lineNo, __VA_ARGS__); \ + } \ } while (0) #define expectToken(expected, lineType) \ do { \ getToken(nullptr, "'%c' line is too short", (lineType)); \ - if (strcasecmp(token, (expected)) != 0) \ + if (strcasecmp(token, (expected)) != 0) { \ fatal( \ &where, \ lineNo, \ @@ -169,6 +171,7 @@ void sdobj_ReadFile(FileStackNode const &where, FILE *file, std::vector (expected), \ token \ ); \ + } \ } while (0) uint32_t lineNo = 0;