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

Commitd5a1fde

Browse files
committed
Remove infinite-loop hazards in ecpg test suite.
A report from Andrew Dunstan showed that an ecpglib breakage thatcauses repeated query failures could lead to infinite loops in someecpg test scripts, because they contain "while(1)" loops with noexit condition other than successful test completion. That mightbe all right for manual testing, but it seems entirely unacceptablefor automated test environments such as our buildfarm. We don'twant buildfarm owners to have to intervene manually when a testgoes wrong.To fix, just change all those while(1) loops to exit after at most100 iterations (which is more than any of them expect to iterate).This seems sufficient since we'd see discrepancies in the test outputif any loop executed the wrong number of times.I tested this by dint of intentionally breaking ecpg_do_prologueto always fail, and verifying that the tests still got to completion.Back-patch to all supported branches, since the whole point of thisexercise is to protect the buildfarm against future mistakes.Discussion:https://postgr.es/m/18693.1548302004@sss.pgh.pa.us
1 parentbbd5c20 commitd5a1fde

18 files changed

+46
-43
lines changed

‎src/interfaces/ecpg/test/compat_informix/test_informix.pgc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ static void dosqlprint(void) {
1111

1212
int main(void)
1313
{
14-
$int i = 14;
14+
$int i = 14, loopcount;
1515
$decimal j, m, n;
1616
$string c[10];
1717

@@ -52,7 +52,7 @@ int main(void)
5252

5353
deccvint(0, &j);
5454

55-
while (1)
55+
for (loopcount = 0; loopcount < 100; loopcount++)
5656
{
5757
$fetch forward c into :i, :j, :c;
5858
if (sqlca.sqlcode == 100) break;

‎src/interfaces/ecpg/test/compat_oracle/char_array.pgc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int main() {
1919
EXEC SQL WHENEVER SQLERROR SQLPRINT;
2020

2121
const char *ppppp = "XXXXX";
22-
22+
int loopcount;
2323
EXEC SQL BEGIN DECLARE SECTION;
2424
char shortstr[5];
2525
char bigstr[11];
@@ -44,7 +44,7 @@ int main() {
4444
EXEC SQL WHENEVER NOT FOUND DO BREAK;
4545

4646
printf("Full Str. : Short Ind.\n");
47-
while(1) {
47+
for (loopcount = 0; loopcount < 100; loopcount++) {
4848
strncpy(shortstr, ppppp, sizeof shortstr);
4949
memset(bigstr, 0, sizeof bigstr);
5050
EXEC SQL FETCH C into :bigstr :bigstr_ind, :shortstr :shstr_ind;

‎src/interfaces/ecpg/test/expected/compat_informix-test_informix.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main(void)
3333
{
3434

3535
#line 14 "test_informix.pgc"
36-
inti=14 ;
36+
inti=14,loopcount;
3737

3838
#line 14 "test_informix.pgc"
3939

@@ -156,7 +156,7 @@ if (sqlca.sqlcode < 0) dosqlprint ( );}
156156

157157
deccvint(0,&j);
158158

159-
while (1)
159+
for (loopcount=0;loopcount<100;loopcount++)
160160
{
161161
{ECPGdo(__LINE__,1,1,NULL,0,ECPGst_normal,"fetch forward c",ECPGt_EOIT,
162162
ECPGt_int,&(i),(long)1,(long)1,sizeof(int),

‎src/interfaces/ecpg/test/expected/compat_oracle-char_array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ int main() {
4141

4242

4343
constchar*ppppp="XXXXX";
44-
44+
intloopcount;
4545
/* exec sql begin declare section */
4646

4747

@@ -156,7 +156,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
156156

157157

158158
printf("Full Str. : Short Ind.\n");
159-
while(1) {
159+
for (loopcount=0;loopcount<100;loopcount++) {
160160
strncpy(shortstr,ppppp,sizeofshortstr);
161161
memset(bigstr,0,sizeofbigstr);
162162
{ECPGdo(__LINE__,3,1,NULL,0,ECPGst_normal,"fetch C",ECPGt_EOIT,

‎src/interfaces/ecpg/test/expected/pgtypeslib-nan_test.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ int
3636
main(void)
3737
{
3838
/* exec sql begin declare section */
39-
39+
4040

4141

4242

4343

4444
#line 21 "nan_test.pgc"
45-
intid ;
45+
intid,loopcount;
4646

4747
#line 22 "nan_test.pgc"
4848
doubled ;
@@ -90,7 +90,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
9090
if (sqlca.sqlcode<0)sqlprint ( );}
9191
#line 36 "nan_test.pgc"
9292

93-
while (1)
93+
for (loopcount=0;loopcount<100;loopcount++)
9494
{
9595
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"fetch from cur",ECPGt_EOIT,
9696
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
@@ -145,7 +145,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
145145
if (sqlca.sqlcode<0)sqlprint ( );}
146146
#line 52 "nan_test.pgc"
147147

148-
while (1)
148+
for (loopcount=0;loopcount<100;loopcount++)
149149
{
150150
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"fetch from cur",ECPGt_EOIT,
151151
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
@@ -229,7 +229,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
229229
if (sqlca.sqlcode<0)sqlprint ( );}
230230
#line 78 "nan_test.pgc"
231231

232-
while (1)
232+
for (loopcount=0;loopcount<100;loopcount++)
233233
{
234234
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"fetch from cur1",ECPGt_EOIT,
235235
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),

‎src/interfaces/ecpg/test/expected/preproc-autoprep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
197197

198198

199199
i=0;
200-
while (1)
200+
while (i<100)
201201
{
202202
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"fetch cur1",ECPGt_EOIT,
203203
ECPGt_int,&(item1),(long)1,(long)1,sizeof(int),

‎src/interfaces/ecpg/test/expected/preproc-outofscope.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ main (void)
267267
{
268268
MYTYPE*myvar;
269269
MYNULLTYPE*mynullvar;
270-
270+
intloopcount;
271271
charmsg[128];
272272

273273
ECPGdebug(1,stderr);
@@ -333,7 +333,7 @@ if (sqlca.sqlcode < 0) exit (1);}
333333
#line 96 "outofscope.pgc"
334334

335335

336-
while (1)
336+
for (loopcount=0;loopcount<100;loopcount++)
337337
{
338338
memset(myvar,0,sizeof(MYTYPE));
339339
get_record1();

‎src/interfaces/ecpg/test/expected/preproc-variable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ main (void)
120120

121121
#line 37 "variable.pgc"
122122

123-
123+
intloopcount;
124124
charmsg[128];
125125

126126
ECPGdebug(1,stderr);
@@ -204,7 +204,7 @@ if (sqlca.sqlcode < 0) exit (1);}
204204
p=&personal;
205205
i=&ind_personal;
206206
memset(i,0,sizeof(ind_personal));
207-
while (1) {
207+
for (loopcount=0;loopcount<100;loopcount++) {
208208
strcpy(msg,"fetch");
209209
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"fetch cur",ECPGt_EOIT,
210210
ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)-1,sizeof(structbirthinfo ),

‎src/interfaces/ecpg/test/expected/preproc-whenever_do_continue.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int main(void)
3333

3434

3535

36-
36+
3737

3838

3939
#line 15 "whenever_do_continue.pgc"
@@ -48,6 +48,9 @@ int main(void)
4848
floatcomm ;
4949
}emp ;
5050

51+
#line 16 "whenever_do_continue.pgc"
52+
intloopcount ;
53+
5154
#line 17 "whenever_do_continue.pgc"
5255
charmsg [128 ] ;
5356
/* exec sql end declare section */
@@ -119,7 +122,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
119122
#line 42 "whenever_do_continue.pgc"
120123

121124

122-
while (1)
125+
for (loopcount=0;loopcount<100;loopcount++)
123126
{
124127
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"fetch c",ECPGt_EOIT,
125128
ECPGt_char,&(emp.ename),(long)12,(long)1,(12)*sizeof(char),

‎src/interfaces/ecpg/test/expected/sql-fetch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
intmain() {
2626
/* exec sql begin declare section */
2727

28-
28+
2929

3030
#line 9 "fetch.pgc"
3131
charstr [25 ] ;
3232

3333
#line 10 "fetch.pgc"
34-
inti ,count=1 ;
34+
inti ,count=1,loopcount;
3535
/* exec sql end declare section */
3636
#line 11 "fetch.pgc"
3737

@@ -112,7 +112,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
112112
/* exec sql whenever not found break ; */
113113
#line 30 "fetch.pgc"
114114

115-
while (1) {
115+
for (loopcount=0;loopcount<100;loopcount++) {
116116
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"fetch 1 in C",ECPGt_EOIT,
117117
ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
118118
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,
@@ -191,7 +191,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
191191
/* exec sql whenever not found break ; */
192192
#line 48 "fetch.pgc"
193193

194-
while (1) {
194+
for (loopcount=0;loopcount<100;loopcount++) {
195195
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"fetch 1 in D",ECPGt_EOIT,
196196
ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
197197
ECPGt_NO_INDICATOR,NULL ,0L,0L,0L,

‎src/interfaces/ecpg/test/expected/sql-quote.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@
2525
intmain() {
2626
/* exec sql begin declare section */
2727

28-
28+
2929

3030
#line 9 "quote.pgc"
3131
charvar [25 ] ;
3232

3333
#line 10 "quote.pgc"
34-
inti ;
34+
inti,loopcount;
3535
/* exec sql end declare section */
3636
#line 11 "quote.pgc"
3737

@@ -176,7 +176,7 @@ if (sqlca.sqlcode < 0) sqlprint();}
176176
#line 47 "quote.pgc"
177177

178178

179-
while (true)
179+
for (loopcount=0;loopcount<100;loopcount++)
180180
{
181181
{ECPGdo(__LINE__,0,1,NULL,0,ECPGst_normal,"fetch C",ECPGt_EOIT,
182182
ECPGt_int,&(i),(long)1,(long)1,sizeof(int),

‎src/interfaces/ecpg/test/pgtypeslib/nan_test.pgc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ int
1818
main(void)
1919
{
2020
exec sql begin declare section;
21-
intid;
21+
intid, loopcount;
2222
doubled;
2323
numeric*num;
2424
charval[16];
@@ -34,7 +34,7 @@ main(void)
3434

3535
exec sql declare cur cursor for select id, d, d from nantest1;
3636
exec sql open cur;
37-
while (1)
37+
for (loopcount = 0; loopcount < 100; loopcount++)
3838
{
3939
exec sql fetch from cur into :id, :d, :val;
4040
if (sqlca.sqlcode)
@@ -50,7 +50,7 @@ main(void)
5050
exec sql close cur;
5151

5252
exec sql open cur;
53-
while (1)
53+
for (loopcount = 0; loopcount < 100; loopcount++)
5454
{
5555
exec sql fetch from cur into :id, :d, :val;
5656
if (sqlca.sqlcode)
@@ -76,7 +76,7 @@ main(void)
7676

7777
exec sql declare cur1 cursor for select id, d, d from nantest2;
7878
exec sql open cur1;
79-
while (1)
79+
for (loopcount = 0; loopcount < 100; loopcount++)
8080
{
8181
exec sql fetch from cur1 into :id, :num, :val;
8282
if (sqlca.sqlcode)

‎src/interfaces/ecpg/test/preproc/autoprep.pgc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void test(void) {
5050
EXEC SQL WHENEVER NOT FOUND DO BREAK;
5151

5252
i = 0;
53-
while (1)
53+
while (i < 100)
5454
{
5555
EXEC SQL FETCH cur1 INTO :item1:ind1;
5656
printf("item[%d] = %d\n", i, ind1 ? -1 : item1);

‎src/interfaces/ecpg/test/preproc/outofscope.pgc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ main (void)
6666
{
6767
MYTYPE*myvar;
6868
MYNULLTYPE*mynullvar;
69-
69+
int loopcount;
7070
char msg[128];
7171

7272
ECPGdebug(1, stderr);
@@ -95,7 +95,7 @@ main (void)
9595

9696
exec sql whenever not found do break;
9797

98-
while (1)
98+
for (loopcount = 0; loopcount < 100; loopcount++)
9999
{
100100
memset(myvar, 0, sizeof(MYTYPE));
101101
get_record1();

‎src/interfaces/ecpg/test/preproc/variable.pgc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ exec sql end declare section;
3535
exec sql char *married = NULL;
3636
exec sql long ind_married;
3737
exec sql ind children;
38-
38+
int loopcount;
3939
char msg[128];
4040

4141
ECPGdebug(1, stderr);
@@ -67,7 +67,7 @@ exec sql end declare section;
6767
p=&personal;
6868
i=&ind_personal;
6969
memset(i, 0, sizeof(ind_personal));
70-
while (1) {
70+
for (loopcount = 0; loopcount < 100; loopcount++) {
7171
strcpy(msg, "fetch");
7272
exec sql fetch cur into :p:i, :married:ind_married, :children.integer:ind_children.smallint;
7373
printf("%8.8s", personal.name.arr);

‎src/interfaces/ecpg/test/preproc/whenever_do_continue.pgc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main(void)
1313
float sal;
1414
float comm;
1515
} emp;
16-
16+
int loopcount;
1717
char msg[128];
1818
exec sql end declare section;
1919

@@ -41,7 +41,7 @@ int main(void)
4141
/* The DO CONTINUE makes the loop start at the next iteration when an error occurs.*/
4242
exec sql whenever sqlerror do continue;
4343

44-
while (1)
44+
for (loopcount = 0; loopcount < 100; loopcount++)
4545
{
4646
exec sql fetch c into :emp;
4747
/* The employees with non-NULL commissions will be displayed. */

‎src/interfaces/ecpg/test/sql/fetch.pgc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ EXEC SQL INCLUDE ../regression;
77
int main() {
88
EXEC SQL BEGIN DECLARE SECTION;
99
char str[25];
10-
int i, count=1;
10+
int i, count=1, loopcount;
1111
EXEC SQL END DECLARE SECTION;
1212

1313
ECPGdebug(1, stderr);
@@ -28,7 +28,7 @@ int main() {
2828
EXEC SQL OPEN C;
2929

3030
EXEC SQL WHENEVER NOT FOUND DO BREAK;
31-
while (1) {
31+
for (loopcount = 0; loopcount < 100; loopcount++) {
3232
EXEC SQL FETCH 1 IN C INTO :i, :str;
3333
printf("%d: %s\n", i, str);
3434
}
@@ -46,7 +46,7 @@ int main() {
4646
EXEC SQL OPEN D using 1;
4747

4848
EXEC SQL WHENEVER NOT FOUND DO BREAK;
49-
while (1) {
49+
for (loopcount = 0; loopcount < 100; loopcount++) {
5050
EXEC SQL FETCH 1 IN D INTO :i, :str;
5151
printf("%d: %s\n", i, str);
5252
}

‎src/interfaces/ecpg/test/sql/quote.pgc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ EXEC SQL INCLUDE ../regression;
77
int main() {
88
EXEC SQL BEGIN DECLARE SECTION;
99
char var[25];
10-
int i;
10+
int i, loopcount;
1111
EXEC SQL END DECLARE SECTION;
1212

1313
ECPGdebug(1, stderr);
@@ -46,7 +46,7 @@ int main() {
4646

4747
EXEC SQL WHENEVER NOT FOUND DO BREAK;
4848

49-
while (true)
49+
for (loopcount = 0; loopcount < 100; loopcount++)
5050
{
5151
EXEC SQL FETCH C INTO :i, :var;
5252
printf("value: %d %s\n", i, var);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp