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

Commit309a04f

Browse files
committed
Add missing "do { ... } while(0)" in ODBC macros and add find_baddefs
script.
1 parent8b4d5c7 commit309a04f

File tree

2 files changed

+36
-12
lines changed

2 files changed

+36
-12
lines changed

‎src/interfaces/odbc/convert.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ static int enlarge_statement(StatementClass *stmt, unsigned int newsize)
796796
*----------
797797
*/
798798
#defineCVT_INIT(size) \
799-
{ \
799+
do{ \
800800
if (stmt->stmt_with_params) \
801801
free(stmt->stmt_with_params); \
802802
if (stmt->stmt_size_limit > 0) \
@@ -811,7 +811,8 @@ static int enlarge_statement(StatementClass *stmt, unsigned int newsize)
811811
stmt->stmt_with_params = new_statement; \
812812
npos = 0; \
813813
new_statement[0] = '\0'; \
814-
}
814+
} while (0)
815+
815816
/*----------
816817
*Terminate the stmt_with_params string with NULL.
817818
*----------
@@ -823,55 +824,59 @@ static int enlarge_statement(StatementClass *stmt, unsigned int newsize)
823824
*----------
824825
*/
825826
#defineCVT_APPEND_DATA(s,len) \
826-
{ \
827+
do{ \
827828
unsigned intnewpos = npos + len; \
828829
ENLARGE_NEWSTATEMENT(newpos) \
829830
memcpy(&new_statement[npos], s, len); \
830831
npos = newpos; \
831832
new_statement[npos] = '\0'; \
832-
}
833+
} while (0)
834+
833835
/*----------
834836
*Append a string.
835837
*----------
836838
*/
837839
#defineCVT_APPEND_STR(s) \
838-
{ \
840+
do{ \
839841
unsigned int len = strlen(s); \
840842
CVT_APPEND_DATA(s, len); \
841-
}
843+
} while (0)
844+
842845
/*----------
843846
*Append a char.
844847
*----------
845848
*/
846849
#defineCVT_APPEND_CHAR(c) \
847-
{ \
850+
do{ \
848851
ENLARGE_NEWSTATEMENT(npos + 1); \
849852
new_statement[npos++] = c; \
850-
}
853+
} while (0)
854+
851855
/*----------
852856
*Append a binary data.
853857
*Newly reqeuired size may be overestimated currently.
854858
*----------
855859
*/
856860
#defineCVT_APPEND_BINARY(buf,used) \
857-
{ \
861+
do{ \
858862
unsigned intnewlimit = npos + 5 * used; \
859863
ENLARGE_NEWSTATEMENT(newlimit); \
860864
npos += convert_to_pgbinary(buf, &new_statement[npos], used); \
861-
}
865+
} while (0)
866+
862867
/*----------
863868
*
864869
*----------
865870
*/
866871
#defineCVT_SPECIAL_CHARS(buf,used) \
867-
{ \
872+
do{ \
868873
intcnvlen = convert_special_chars(buf, NULL, used); \
869874
unsigned intnewlimit = npos + cnvlen; \
870875
\
871876
ENLARGE_NEWSTATEMENT(newlimit); \
872877
convert_special_chars(buf, &new_statement[npos], used); \
873878
npos += cnvlen; \
874-
}
879+
} while (0)
875880

876881
/*----------
877882
*Check if the statement is

‎src/tools/find_baddefs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
# This script attempts to find bad ifdef's, i.e. ifdef's that use braces
3+
# but not the do { ... } while (0) syntax
4+
#
5+
# This is useful for running before pgindent
6+
7+
for FILE
8+
do
9+
awk'BEGIN{was_define = "N"}
10+
{ if (was_define == "Y" &&
11+
$0 ~ /^{/)
12+
printf "%s %d\n", FILENAME, NR
13+
if ($0 ~ /^#define/)
14+
was_define = "Y"
15+
else
16+
was_define = "N"
17+
}'$FILE
18+
done
19+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp