Skip to content

Commit 49718aa

Browse files
committed
Get rid of trailing semicolons in C macro definitions.
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
1 parent 072a863 commit 49718aa

File tree

11 files changed

+22
-19
lines changed

11 files changed

+22
-19
lines changed

contrib/btree_gist/btree_ts.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,13 @@ gbt_ts_union(PG_FUNCTION_ARGS)
344344
}
345345

346346

347-
#define penalty_check_max_float(val) do { \
347+
#define penalty_check_max_float(val) \
348+
do { \
348349
if ( val > FLT_MAX ) \
349350
val = FLT_MAX; \
350351
if ( val < -FLT_MAX ) \
351352
val = -FLT_MAX; \
352-
} while(false);
353+
} while (0)
353354

354355

355356
Datum

contrib/btree_gist/btree_utils_num.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ typedef struct
7474
(*(result)) += (float) ( ((double)(tmp)) / ( (double)(tmp) + ( ((double)(oupper))*0.49F - ((double)(olower))*0.49F ) ) ); \
7575
(*(result)) *= (FLT_MAX / (((GISTENTRY *) PG_GETARG_POINTER(0))->rel->rd_att->natts + 1)); \
7676
} \
77-
} while (0);
77+
} while (0)
7878

7979

8080
/*

contrib/pg_trgm/trgm.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ typedef char trgm[3];
4545
*(((char*)(a))+0) = *(((char*)(b))+0); \
4646
*(((char*)(a))+1) = *(((char*)(b))+1); \
4747
*(((char*)(a))+2) = *(((char*)(b))+2); \
48-
} while(0);
48+
} while(0)
4949

5050
#ifdef KEEPONLYALNUM
5151
#define ISWORDCHR(c) (t_isalpha(c) || t_isdigit(c))

contrib/pgcrypto/crypt-blowfish.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ BF_swap(BF_word *x, int count)
469469
tmp3 ^= tmp2; \
470470
(R) ^= data.ctx.P[(N) + 1]; \
471471
tmp3 += tmp1; \
472-
(R) ^= tmp3;
472+
(R) ^= tmp3
473473
#else
474474
/* Architectures with no complicated addressing modes supported */
475475
#define BF_INDEX(S, i) \
@@ -490,7 +490,7 @@ BF_swap(BF_word *x, int count)
490490
tmp3 ^= tmp2; \
491491
(R) ^= data.ctx.P[(N) + 1]; \
492492
tmp3 += tmp1; \
493-
(R) ^= tmp3;
493+
(R) ^= tmp3
494494
#endif
495495

496496
/*
@@ -516,17 +516,18 @@ BF_swap(BF_word *x, int count)
516516
BF_ROUND(R, L, 15); \
517517
tmp4 = R; \
518518
R = L; \
519-
L = tmp4 ^ data.ctx.P[BF_N + 1];
519+
L = tmp4 ^ data.ctx.P[BF_N + 1]
520520

521521
#if BF_ASM
522522

523523
extern void _BF_body_r(BF_ctx *ctx);
524524

525525
#define BF_body() \
526-
_BF_body_r(&data.ctx);
526+
_BF_body_r(&data.ctx)
527527
#else
528528

529529
#define BF_body() \
530+
do { \
530531
L = R = 0; \
531532
ptr = data.ctx.P; \
532533
do { \
@@ -542,7 +543,8 @@ extern void _BF_body_r(BF_ctx *ctx);
542543
BF_ENCRYPT; \
543544
*(ptr - 2) = L; \
544545
*(ptr - 1) = R; \
545-
} while (ptr < &data.ctx.S[3][0xFF]);
546+
} while (ptr < &data.ctx.S[3][0xFF]); \
547+
} while (0)
546548
#endif
547549

548550
static void

src/backend/nodes/readfuncs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,22 +136,22 @@
136136
/* Read an attribute number array */
137137
#define READ_ATTRNUMBER_ARRAY(fldname, len) \
138138
token = pg_strtok(&length); /* skip :fldname */ \
139-
local_node->fldname = readAttrNumberCols(len);
139+
local_node->fldname = readAttrNumberCols(len)
140140

141141
/* Read an oid array */
142142
#define READ_OID_ARRAY(fldname, len) \
143143
token = pg_strtok(&length); /* skip :fldname */ \
144-
local_node->fldname = readOidCols(len);
144+
local_node->fldname = readOidCols(len)
145145

146146
/* Read an int array */
147147
#define READ_INT_ARRAY(fldname, len) \
148148
token = pg_strtok(&length); /* skip :fldname */ \
149-
local_node->fldname = readIntCols(len);
149+
local_node->fldname = readIntCols(len)
150150

151151
/* Read a bool array */
152152
#define READ_BOOL_ARRAY(fldname, len) \
153153
token = pg_strtok(&length); /* skip :fldname */ \
154-
local_node->fldname = readBoolCols(len);
154+
local_node->fldname = readBoolCols(len)
155155

156156
/* Routine exit */
157157
#define READ_DONE() \

src/backend/utils/adt/formatting.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ typedef struct
430430
(_X)->mode, (_X)->hh, (_X)->pm, (_X)->mi, (_X)->ss, (_X)->ssss, \
431431
(_X)->d, (_X)->dd, (_X)->ddd, (_X)->mm, (_X)->ms, (_X)->year, \
432432
(_X)->bc, (_X)->ww, (_X)->w, (_X)->cc, (_X)->j, (_X)->us, \
433-
(_X)->yysz, (_X)->clock);
433+
(_X)->yysz, (_X)->clock)
434434
#define DEBUG_TM(_X) \
435435
elog(DEBUG_elog_output, "TM:\nsec %d\nyear %d\nmin %d\nwday %d\nhour %d\nyday %d\nmday %d\nnisdst %d\nmon %d\n",\
436436
(_X)->tm_sec, (_X)->tm_year,\

src/backend/utils/sort/gen_qsort_tuple.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ sub emit_qsort_boilerplate
125125
SortTuple t = *(a); \
126126
*(a) = *(b); \
127127
*(b) = t; \
128-
} while (0);
128+
} while (0)
129129
130130
#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n)
131131

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ typedef z_stream *z_streamp;
9999
#define K_VERS_MAJOR 1
100100
#define K_VERS_MINOR 13
101101
#define K_VERS_REV 0
102-
#define K_VERS_SELF MAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, K_VERS_REV);
102+
#define K_VERS_SELF MAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, K_VERS_REV)
103103

104104
/* Newest format we can read */
105105
#define K_VERS_MAX MAKE_ARCHIVE_VERSION(K_VERS_MAJOR, K_VERS_MINOR, 255)

src/include/access/nbtree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ typedef BTScanPosData *BTScanPos;
359359
(scanpos).buf = InvalidBuffer; \
360360
(scanpos).lsn = InvalidXLogRecPtr; \
361361
(scanpos).nextTupleOffset = 0; \
362-
} while (0);
362+
} while (0)
363363

364364
/* We need one of these for each equality-type SK_SEARCHARRAY scan key */
365365
typedef struct BTArrayKeyInfo

src/port/qsort.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ do { \
8080
} while (0)
8181

8282
#define SWAPINIT(a, es) swaptype = ((char *)(a) - (char *)0) % sizeof(long) || \
83-
(es) % sizeof(long) ? 2 : (es) == sizeof(long)? 0 : 1;
83+
(es) % sizeof(long) ? 2 : (es) == sizeof(long)? 0 : 1
8484

8585
static void
8686
swapfunc(char *a, char *b, size_t n, int swaptype)

src/port/qsort_arg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ do { \
8080
} while (0)
8181

8282
#define SWAPINIT(a, es) swaptype = ((char *)(a) - (char *)0) % sizeof(long) || \
83-
(es) % sizeof(long) ? 2 : (es) == sizeof(long)? 0 : 1;
83+
(es) % sizeof(long) ? 2 : (es) == sizeof(long)? 0 : 1
8484

8585
static void
8686
swapfunc(char *a, char *b, size_t n, int swaptype)

0 commit comments

Comments
 (0)