Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfde8eda

Browse files
committed
Add do { ... } while (0) to more bad macros.
1 parentb4a57b0 commitfde8eda

File tree

13 files changed

+89
-42
lines changed

13 files changed

+89
-42
lines changed

‎contrib/fuzzystrmatch/fuzzystrmatch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ char Lookahead(char * word, int how_far) {
280280

281281

282282
/* phonize one letter */
283-
#definePhonize(c){(*phoned_word)[p_idx++] = c;}
283+
#definePhonize(c)do{(*phoned_word)[p_idx++] = c;} while (0)
284284
/* Slap a null character on the end of the phoned word */
285-
#defineEnd_Phoned_Word{(*phoned_word)[p_idx] = '\0';}
285+
#defineEnd_Phoned_Worddo{(*phoned_word)[p_idx] = '\0';} while (0)
286286
/* How long is the phoned word? */
287287
#definePhone_Len(p_idx)
288288

‎contrib/pgcrypto/md5.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*$Id: md5.c,v 1.6 2001/08/21 00:42:41 momjian Exp $*/
1+
/*$Id: md5.c,v 1.7 2001/10/25 01:29:37 momjian Exp $*/
22
/* $KAME: md5.c,v 1.3 2000/02/22 14:01:17 itojun Exp $ */
33

44
/*
@@ -41,29 +41,33 @@
4141
#defineH(X,Y,Z) ((X) ^ (Y) ^ (Z))
4242
#defineI(X,Y,Z) ((Y) ^ ((X) | (~Z)))
4343

44-
#defineROUND1(a,b,c,d,k,s,i) { \
44+
#defineROUND1(a,b,c,d,k,s,i) \
45+
do { \
4546
(a) = (a) + F((b), (c), (d)) + X[(k)] + T[(i)]; \
4647
(a) = SHIFT((a), (s)); \
4748
(a) = (b) + (a); \
48-
}
49+
} while (0)
4950

50-
#defineROUND2(a,b,c,d,k,s,i) { \
51+
#defineROUND2(a,b,c,d,k,s,i) \
52+
do { \
5153
(a) = (a) + G((b), (c), (d)) + X[(k)] + T[(i)]; \
5254
(a) = SHIFT((a), (s)); \
5355
(a) = (b) + (a); \
54-
}
56+
} while (0)
5557

56-
#defineROUND3(a,b,c,d,k,s,i) { \
58+
#defineROUND3(a,b,c,d,k,s,i) \
59+
do { \
5760
(a) = (a) + H((b), (c), (d)) + X[(k)] + T[(i)]; \
5861
(a) = SHIFT((a), (s)); \
5962
(a) = (b) + (a); \
60-
}
63+
} while (0)
6164

62-
#defineROUND4(a,b,c,d,k,s,i) { \
65+
#defineROUND4(a,b,c,d,k,s,i) \
66+
do { \
6367
(a) = (a) + I((b), (c), (d)) + X[(k)] + T[(i)]; \
6468
(a) = SHIFT((a), (s)); \
6569
(a) = (b) + (a); \
66-
}
70+
} while (0)
6771

6872
#defineSa 7
6973
#defineSb12

‎contrib/pgcrypto/sha1.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*$Id: sha1.c,v 1.6 2001/08/21 00:42:41 momjian Exp $ */
1+
/*$Id: sha1.c,v 1.7 2001/10/25 01:29:37 momjian Exp $ */
22
/* $KAME: sha1.c,v 1.3 2000/02/22 14:01:18 itojun Exp $ */
33

44
/*
@@ -65,22 +65,24 @@ static uint32 _K[] = {0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6};
6565
#defineBCOUNT(ctxt->c.b64[0] / 8)
6666
#defineW(n)(ctxt->m.b32[(n)])
6767

68-
#definePUTBYTE(x){ \
68+
#definePUTBYTE(x) \
69+
do { \
6970
ctxt->m.b8[(COUNT % 64)] = (x);\
7071
COUNT++;\
7172
COUNT %= 64;\
7273
ctxt->c.b64[0] += 8;\
7374
if (COUNT % 64 == 0)\
7475
sha1_step(ctxt);\
75-
}
76+
} while (0)
7677

77-
#definePUTPAD(x){ \
78+
#definePUTPAD(x) \
79+
do { \
7880
ctxt->m.b8[(COUNT % 64)] = (x);\
7981
COUNT++;\
8082
COUNT %= 64;\
8183
if (COUNT % 64 == 0)\
8284
sha1_step(ctxt);\
83-
}
85+
} while (0)
8486

8587
staticvoidsha1_step(structsha1_ctxt*);
8688

‎contrib/tsearch/query.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,9 @@ typedef struct {
555555
int4buflen;
556556
}INFIX;
557557

558-
#defineRESIZEBUF(inf,addsize) while( ( inf->cur - inf->buf ) + addsize + 1 >= inf->buflen ) { \
558+
#defineRESIZEBUF(inf,addsize) \
559+
while( ( inf->cur - inf->buf ) + addsize + 1 >= inf->buflen ) \
560+
{ \
559561
int4 len = inf->cur - inf->buf; \
560562
inf->buflen *= 2; \
561563
inf->buf = (char*) repalloc( (void*)inf->buf, inf->buflen ); \

‎contrib/tsearch/txtidx.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,16 @@ uniqueentry( WordEntry* a, int4 l, char *buf, int4 *outbuflen ) {
8888
#defineWAITNEXTCHAR3
8989
#defineWAITENDCMPLX4
9090

91-
#defineRESIZEPRSBUF if ( state->curpos - state->word == state->len ) { \
91+
#defineRESIZEPRSBUF \
92+
do { \
93+
if ( state->curpos - state->word == state->len ) \
94+
{ \
9295
int4 clen = state->curpos - state->word; \
9396
state->len *= 2; \
9497
state->word = (char*)repalloc( (void*)state->word, state->len ); \
9598
state->curpos = state->word + clen; \
96-
}
99+
} \
100+
} while (0)
97101

98102
int4
99103
gettoken_txtidx(TI_IN_STATE*state ) {

‎src/backend/port/dynloader/bsdi.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@
2727
#else/* not HAVE_DLOPEN */
2828

2929
#definepg_dlsym(handle,funcname) ((PGFunction) dld_get_func((funcname)))
30-
#definepg_dlclose(handle) ({ dld_unlink_by_file(handle, 1); free(handle); })
30+
#definepg_dlclose(handle) \
31+
do { \
32+
dld_unlink_by_file(handle, 1); \
33+
free(handle); \
34+
} while (0)
3135

3236
#endif/* not HAVE_DLOPEN */
3337

‎src/backend/port/dynloader/linux.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
77
* Portions Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: linux.h,v 1.12 2001/05/14 21:45:53 petere Exp $
9+
* $Id: linux.h,v 1.13 2001/10/25 01:29:37 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -23,10 +23,15 @@
2323

2424
#ifndefHAVE_DLD_H
2525
#definepg_dlsym(handle,funcname)(NULL)
26-
#definepg_dlclose(handle)({})
26+
#definepg_dlclose(handle){}
2727
#else
2828
#definepg_dlsym(handle,funcname)((PGFunction) dld_get_func((funcname)))
29-
#definepg_dlclose(handle) ({ dld_unlink_by_file(handle, 1); free(handle); })
29+
#definepg_dlclose(handle) \
30+
do { \
31+
dld_unlink_by_file(handle, 1); \
32+
free(handle); \
33+
} while (0)
34+
3035
#endif
3136

3237
#else/* HAVE_DLOPEN */

‎src/backend/regex/engine.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,12 @@ static intpg_isprint(int c);
129129
#ifdefREDEBUG
130130
#defineSP(t,s,c)print(m, t, s, c, stdout)
131131
#defineAT(t,p1,p2,s1,s2)at(m, t, p1, p2, s1, s2)
132-
#defineNOTE(str){ if (m->eflags&REG_TRACE) printf("=%s\n", (str)); }
132+
#defineNOTE(str) \
133+
do { \
134+
if (m->eflags&REG_TRACE) \
135+
printf("=%s\n", (str)); \
136+
} while (0)
137+
133138
#else
134139
#defineSP(t,s,c)/* nothing */
135140
#defineAT(t,p1,p2,s1,s2)/* nothing */

‎src/backend/regex/regexec.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,19 @@ static intnope = 0;/* for use in asserts; shuts lint up */
114114
#defineASSIGN(d,s)memcpy(d, s, m->g->nstates)
115115
#defineEQ(a,b)(memcmp(a, b, m->g->nstates) == 0)
116116
#defineSTATEVARSint vn; char *space
117-
#defineSTATESETUP(m,nv){ (m)->space = malloc((nv)*(m)->g->nstates); \
118-
if ((m)->space == NULL) return(REG_ESPACE); \
119-
(m)->vn = 0; }
120-
#defineSTATETEARDOWN(m){ free((m)->space); }
117+
#defineSTATESETUP(m,nv) \
118+
do { \
119+
(m)->space = malloc((nv)*(m)->g->nstates); \
120+
if ((m)->space == NULL) \
121+
return(REG_ESPACE); \
122+
(m)->vn = 0; \
123+
} while (0)
124+
125+
#defineSTATETEARDOWN(m) \
126+
do { \
127+
free((m)->space); \
128+
} while (0)
129+
121130
#defineSETUP(v)((v) = &m->space[m->vn++ * m->g->nstates])
122131
#defineonestateint
123132
#defineINIT(o,n)((o) = (n))

‎src/backend/utils/adt/pg_lzcompress.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ----------
22
* pg_lzcompress.c -
33
*
4-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.11 2001/03/22 06:16:17 momjian Exp $
4+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/pg_lzcompress.c,v 1.12 2001/10/25 01:29:37 momjian Exp $
55
*
66
*This is an implementation of LZ compression for PostgreSQL.
77
*It uses a simple history table and generates 2-3 byte tags
@@ -283,7 +283,8 @@ static PGLZ_HistEntry hist_entries[PGLZ_HISTORY_SIZE];
283283
*Adds a new entry to the history table.
284284
* ----------
285285
*/
286-
#definepglz_hist_add(_hs,_he,_hn,_s,_e) {\
286+
#definepglz_hist_add(_hs,_he,_hn,_s,_e) \
287+
do {\
287288
int __hindex = pglz_hist_idx((_s),(_e));\
288289
if ((_he)[(_hn)].prev == NULL) {\
289290
(_hs)[__hindex] = (_he)[(_hn)].next;\
@@ -303,7 +304,7 @@ static PGLZ_HistEntry hist_entries[PGLZ_HISTORY_SIZE];
303304
if (++(_hn) >= PGLZ_HISTORY_SIZE) {\
304305
(_hn) = 0;\
305306
}\
306-
}
307+
} while (0)
307308

308309

309310
/* ----------
@@ -312,15 +313,16 @@ static PGLZ_HistEntry hist_entries[PGLZ_HISTORY_SIZE];
312313
*Outputs the last and allocates a new control byte if needed.
313314
* ----------
314315
*/
315-
#definepglz_out_ctrl(__ctrlp,__ctrlb,__ctrl,__buf) {\
316+
#definepglz_out_ctrl(__ctrlp,__ctrlb,__ctrl,__buf) \
317+
do { \
316318
if ((__ctrl & 0xff) == 0)\
317319
{\
318320
*__ctrlp = __ctrlb;\
319321
__ctrlp = __buf++;\
320322
__ctrlb = 0;\
321323
__ctrl = 1;\
322324
}\
323-
}
325+
} while (0)
324326

325327

326328
/* ----------
@@ -330,11 +332,12 @@ static PGLZ_HistEntry hist_entries[PGLZ_HISTORY_SIZE];
330332
*appropriate control bit.
331333
* ----------
332334
*/
333-
#definepglz_out_literal(_ctrlp,_ctrlb,_ctrl,_buf,_byte) {\
335+
#definepglz_out_literal(_ctrlp,_ctrlb,_ctrl,_buf,_byte) \
336+
do { \
334337
pglz_out_ctrl(_ctrlp,_ctrlb,_ctrl,_buf);\
335338
*_buf++ = (unsigned char)(_byte);\
336339
_ctrl <<= 1;\
337-
}
340+
} while (0)
338341

339342

340343
/* ----------
@@ -345,7 +348,8 @@ static PGLZ_HistEntry hist_entries[PGLZ_HISTORY_SIZE];
345348
*appropriate control bit.
346349
* ----------
347350
*/
348-
#definepglz_out_tag(_ctrlp,_ctrlb,_ctrl,_buf,_len,_off) {\
351+
#definepglz_out_tag(_ctrlp,_ctrlb,_ctrl,_buf,_len,_off) \
352+
do { \
349353
pglz_out_ctrl(_ctrlp,_ctrlb,_ctrl,_buf);\
350354
_ctrlb |= _ctrl;\
351355
_ctrl <<= 1;\
@@ -360,7 +364,7 @@ static PGLZ_HistEntry hist_entries[PGLZ_HISTORY_SIZE];
360364
_buf[1] = (unsigned char)((_off) & 0xff);\
361365
_buf += 2;\
362366
}\
363-
}
367+
} while (0)
364368

365369

366370
/* ----------

‎src/interfaces/odbc/convert.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,10 @@ do { \
817817
*Terminate the stmt_with_params string with NULL.
818818
*----------
819819
*/
820-
#defineCVT_TERMINATE { new_statement[npos] = '\0'; }
820+
#defineCVT_TERMINATE \
821+
do { \
822+
new_statement[npos] = '\0'; \
823+
} while (0)
821824

822825
/*----------
823826
*Append a data.
@@ -1434,7 +1437,7 @@ copy_statement_with_parameters(StatementClass *stmt)
14341437
/* error */
14351438
stmt->errormsg="Unrecognized C_parameter type in copy_statement_with_parameters";
14361439
stmt->errornumber=STMT_NOT_IMPLEMENTED_ERROR;
1437-
CVT_TERMINATE/* just in case */
1440+
CVT_TERMINATE;/* just in case */
14381441
SC_log_error(func,"",stmt);
14391442
returnSQL_ERROR;
14401443
}
@@ -1684,7 +1687,7 @@ copy_statement_with_parameters(StatementClass *stmt)
16841687
}/* end, for */
16851688

16861689
/* make sure new_statement is always null-terminated */
1687-
CVT_TERMINATE
1690+
CVT_TERMINATE;
16881691

16891692
if (conn->DriverToDataSource!=NULL)
16901693
{

‎src/interfaces/odbc/iodbc.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
#include<sys/types.h>
99

1010
#defineMEM_ALLOC(size)(malloc((size_t)(size)))
11-
#defineMEM_FREE(ptr){if(ptr) free(ptr);}
11+
#defineMEM_FREE(ptr)\
12+
do { \
13+
if(ptr) \
14+
free(ptr); \
15+
} while (0)
1216

1317
#defineSTRCPY(t,s)(strcpy((char*)(t), (char*)(s)))
1418
#defineSTRNCPY(t,s,n)(strncpy((char*)(t), (char*)(s), (size_t)(n)))

‎src/tools/find_baddefs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ do
1414
was_define = "Y"
1515
else
1616
was_define = "N"
17-
}'$FILE
17+
}'"$FILE"
18+
grep -on'^#define.*{'"$FILE"| grep -v'do[ ]*{'
1819
done
1920

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp