Get rid of trailing semicolons in C macro definitions.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 1 May 2020 21:28:00 +0000 (17:28 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 1 May 2020 21:28:00 +0000 (17:28 -0400)
Writing a trailing semicolon in a macro is almost never the right thing,
because you almost always want to write a semicolon after each macro
call instead.  (Even if there was some reason to prefer not to, pgindent
would probably make a hash of code formatted that way; so within PG the
rule should basically be "don't do it".)  Thus, if we have a semi inside
the macro, the compiler sees "something;;".  Much of the time the extra
empty statement is harmless, but it could lead to mysterious syntax
errors at call sites.  In perhaps an overabundance of neatnik-ism, let's
run around and get rid of the excess semicolons whereever possible.

The only thing worse than a mysterious syntax error is a mysterious
syntax error that only happens in the back branches; therefore,
backpatch these changes where relevant, which is most of them because
most of these mistakes are old.  (The lack of reported problems shows
that this is largely a hypothetical issue, but still, it could bite
us in some future patch.)

John Naylor and Tom Lane

Discussion: https://postgr.es/m/CACPNZCs0qWTqJ2QUSGJ07B7uvAvzMb-KbG2q+oo+J3tsWN5cqw@mail.gmail.com

13 files changed:
contrib/btree_gist/btree_ts.c
contrib/btree_gist/btree_utils_num.h
contrib/pg_trgm/trgm.h
contrib/pgcrypto/crypt-blowfish.c
src/backend/nodes/readfuncs.c
src/backend/optimizer/util/pathnode.c
src/backend/utils/adt/formatting.c
src/backend/utils/sort/gen_qsort_tuple.pl
src/bin/pg_dump/pg_backup_archiver.h
src/include/access/hash.h
src/include/access/nbtree.h
src/port/qsort.c
src/port/qsort_arg.c

index 3b07969dee86145c13a81b334268e5a80457635f..2671ba961cdae67ec9fa4f180fe083bf38e3a60d 100644 (file)
@@ -341,12 +341,13 @@ gbt_ts_union(PG_FUNCTION_ARGS)
 }
 
 
-#define penalty_check_max_float(val) do { \
+#define penalty_check_max_float(val) \
+   do { \
        if ( val > FLT_MAX ) \
                val = FLT_MAX; \
        if ( val < -FLT_MAX ) \
                val = -FLT_MAX; \
-} while(false);
+   } while (0)
 
 
 Datum
index 1fedfbe82daa6724a65a00176ce0fd4c46ce6ab7..cec69861726f90c9db68c4b30cb1e36d5e340f8e 100644 (file)
@@ -74,7 +74,7 @@ typedef struct
    (*(result)) += (float) ( ((double)(tmp)) / ( (double)(tmp) + ( ((double)(oupper))*0.49F - ((double)(olower))*0.49F ) ) ); \
    (*(result)) *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1)); \
   } \
-} while (0);
+} while (0)
 
 
 /*
index 0c34b96d8080904760b1ef96726a87e39c8b3577..b616953462e685c7494bec05195b27ffb0247583 100644 (file)
@@ -48,7 +48,7 @@ typedef char trgm[3];
    *(((char*)(a))+0) = *(((char*)(b))+0);  \
    *(((char*)(a))+1) = *(((char*)(b))+1);  \
    *(((char*)(a))+2) = *(((char*)(b))+2);  \
-} while(0);
+} while(0)
 
 #ifdef KEEPONLYALNUM
 #define ISWORDCHR(c)   (t_isalpha(c) || t_isdigit(c))
index ed69c0c6bb35ec7cc2337ec05a40a850507145f9..a663852ccf90c36d0d1962ff5f0d29e3aaf95983 100644 (file)
@@ -469,7 +469,7 @@ BF_swap(BF_word *x, int count)
    tmp3 ^= tmp2; \
    (R) ^= data.ctx.P[(N) + 1]; \
    tmp3 += tmp1; \
-   (R) ^= tmp3;
+   (R) ^= tmp3
 #else
 /* Architectures with no complicated addressing modes supported */
 #define BF_INDEX(S, i) \
@@ -490,7 +490,7 @@ BF_swap(BF_word *x, int count)
    tmp3 ^= tmp2; \
    (R) ^= data.ctx.P[(N) + 1]; \
    tmp3 += tmp1; \
-   (R) ^= tmp3;
+   (R) ^= tmp3
 #endif
 
 /*
@@ -516,17 +516,18 @@ BF_swap(BF_word *x, int count)
    BF_ROUND(R, L, 15); \
    tmp4 = R; \
    R = L; \
-   L = tmp4 ^ data.ctx.P[BF_N + 1];
+   L = tmp4 ^ data.ctx.P[BF_N + 1]
 
 #if BF_ASM
 
 extern void _BF_body_r(BF_ctx *ctx);
 
 #define BF_body() \
-   _BF_body_r(&data.ctx);
+   _BF_body_r(&data.ctx)
 #else
 
 #define BF_body() \
+do { \
    L = R = 0; \
    ptr = data.ctx.P; \
    do { \
@@ -542,7 +543,8 @@ extern void _BF_body_r(BF_ctx *ctx);
        BF_ENCRYPT; \
        *(ptr - 2) = L; \
        *(ptr - 1) = R; \
-   } while (ptr < &data.ctx.S[3][0xFF]);
+   } while (ptr < &data.ctx.S[3][0xFF]); \
+} while (0)
 #endif
 
 static void
index 644e0f5fc734e360eead718bae5d8cb28d3a0f4d..eb01584a5f667275413446ee62840dacf8ec2a8b 100644 (file)
 /* Read an attribute number array */
 #define READ_ATTRNUMBER_ARRAY(fldname, len) \
    token = pg_strtok(&length);     /* skip :fldname */ \
-   local_node->fldname = readAttrNumberCols(len);
+   local_node->fldname = readAttrNumberCols(len)
 
 /* Read an oid array */
 #define READ_OID_ARRAY(fldname, len) \
    token = pg_strtok(&length);     /* skip :fldname */ \
-   local_node->fldname = readOidCols(len);
+   local_node->fldname = readOidCols(len)
 
 /* Read an int array */
 #define READ_INT_ARRAY(fldname, len) \
    token = pg_strtok(&length);     /* skip :fldname */ \
-   local_node->fldname = readIntCols(len);
+   local_node->fldname = readIntCols(len)
 
 /* Read a bool array */
 #define READ_BOOL_ARRAY(fldname, len) \
    token = pg_strtok(&length);     /* skip :fldname */ \
-   local_node->fldname = readBoolCols(len);
+   local_node->fldname = readBoolCols(len)
 
 /* Routine exit */
 #define READ_DONE() \
index e991385059fa52b3333ca215dd6b03d7762628b1..d09bc6d291a148b7683f6533ecefc4812fa666f2 100644 (file)
@@ -3859,7 +3859,7 @@ do { \
    (path) = reparameterize_path_by_child(root, (path), child_rel); \
    if ((path) == NULL) \
        return NULL; \
-} while(0);
+} while(0)
 
 #define REPARAMETERIZE_CHILD_PATH_LIST(pathlist) \
 do { \
@@ -3870,7 +3870,7 @@ do { \
        if ((pathlist) == NIL) \
            return NULL; \
    } \
-} while(0);
+} while(0)
 
    Path       *new_path;
    ParamPathInfo *new_ppi;
index 95f7d0538e0bfe02a6eb9571422df6f71206b938..aab5802edb4674391155f9e8912f738ec698991c 100644 (file)
@@ -479,7 +479,7 @@ typedef struct
            (_X)->mode, (_X)->hh, (_X)->pm, (_X)->mi, (_X)->ss, (_X)->ssss, \
            (_X)->d, (_X)->dd, (_X)->ddd, (_X)->mm, (_X)->ms, (_X)->year, \
            (_X)->bc, (_X)->ww, (_X)->w, (_X)->cc, (_X)->j, (_X)->us, \
-           (_X)->yysz, (_X)->clock);
+           (_X)->yysz, (_X)->clock)
 #define DEBUG_TM(_X) \
        elog(DEBUG_elog_output, "TM:\nsec %d\nyear %d\nmin %d\nwday %d\nhour %d\nyday %d\nmday %d\nnisdst %d\nmon %d\n",\
            (_X)->tm_sec, (_X)->tm_year,\
@@ -2731,11 +2731,13 @@ DCH_to_char(FormatNode *node, bool is_interval, TmToChar *in, char *out, Oid col
                    str_numth(s, s, S_TH_TYPE(n->suffix));
                s += strlen(s);
                break;
+
 #define DCH_to_char_fsec(frac_fmt, frac_val) \
                sprintf(s, frac_fmt, (int) (frac_val)); \
                if (S_THth(n->suffix)) \
                    str_numth(s, s, S_TH_TYPE(n->suffix)); \
-               s += strlen(s);
+               s += strlen(s)
+
            case DCH_FF1:       /* tenth of second */
                DCH_to_char_fsec("%01d", in->fsec / 100000);
                break;
index 9ed6cfc7eaa76d530cdecea9d36afe3e2abbb489..eb0f7c5814f4b9e53fb563618944af60e0012d53 100644 (file)
@@ -126,7 +126,7 @@ swapfunc(SortTuple *a, SortTuple *b, size_t n)
        SortTuple t = *(a);             \
        *(a) = *(b);                    \
        *(b) = t;                       \
-   } while (0);
+   } while (0)
 
 #define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n)
 
index 67f34743b80f5c123a36a5adc0ec3aa30ad79959..f9e6b42752af627b27da485ef2e9bfa7ae9b3091 100644 (file)
@@ -98,7 +98,7 @@ typedef z_stream *z_streamp;
 #define K_VERS_MAJOR 1
 #define K_VERS_MINOR 14
 #define K_VERS_REV 0
-#define K_VERS_SELF MAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, K_VERS_REV);
+#define K_VERS_SELF MAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, K_VERS_REV)
 
 /* Newest format we can read */
 #define K_VERS_MAX MAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, 255)
index 94b643cc7794d1da4c07a91ffc7f26498d45fe58..7e7b1b73d86d151858688802b7eb0e3e671c6d55 100644 (file)
@@ -148,7 +148,7 @@ typedef struct HashScanPosData
        (scanpos).firstItem = 0; \
        (scanpos).lastItem = 0; \
        (scanpos).itemIndex = 0; \
-   } while (0);
+   } while (0)
 
 /*
  * HashScanOpaqueData is private state for a hash index scan.
index 97c96d0a3a3ed66e3d3328a47323fbcc5b9c108f..44a472d76b6b24cf20e14b14659409b9b35a63a4 100644 (file)
@@ -888,7 +888,7 @@ typedef BTScanPosData *BTScanPos;
        (scanpos).buf = InvalidBuffer; \
        (scanpos).lsn = InvalidXLogRecPtr; \
        (scanpos).nextTupleOffset = 0; \
-   } while (0);
+   } while (0)
 
 /* We need one of these for each equality-type SK_SEARCHARRAY scan key */
 typedef struct BTArrayKeyInfo
index 409f69a128b5f2a853f55d4fe98ee735644e981f..fa992e2081df5d7756fef0a12c240e19d1f3184a 100644 (file)
@@ -80,7 +80,7 @@ do {      \
 } while (0)
 
 #define SWAPINIT(a, es) swaptype = ((char *)(a) - (char *)0) % sizeof(long) || \
-   (es) % sizeof(long) ? 2 : (es) == sizeof(long)? 0 : 1;
+   (es) % sizeof(long) ? 2 : (es) == sizeof(long)? 0 : 1
 
 static void
 swapfunc(char *a, char *b, size_t n, int swaptype)
index a2194b0fb186da2befdffe47e26946178d00ef5d..6d54fbc2b42541e7f1d5b071ca283fec734720b6 100644 (file)
@@ -80,7 +80,7 @@ do {      \
 } while (0)
 
 #define SWAPINIT(a, es) swaptype = ((char *)(a) - (char *)0) % sizeof(long) || \
-   (es) % sizeof(long) ? 2 : (es) == sizeof(long)? 0 : 1;
+   (es) % sizeof(long) ? 2 : (es) == sizeof(long)? 0 : 1
 
 static void
 swapfunc(char *a, char *b, size_t n, int swaptype)