Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit adc2553

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

14 files changed

+35
-35
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/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-
int i = 14 ;
36+
int i = 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/pgtypeslib-nan_test.c

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

3939

4040

4141

4242
#line 19 "nan_test.pgc"
43-
int id ;
43+
int id , loopcount ;
4444

4545
#line 20 "nan_test.pgc"
4646
double d ;
@@ -88,7 +88,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
8888
if (sqlca.sqlcode < 0) sqlprint ( );}
8989
#line 34 "nan_test.pgc"
9090

91-
while (1)
91+
for (loopcount = 0; loopcount < 100; loopcount++)
9292
{
9393
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
9494
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
@@ -143,7 +143,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
143143
if (sqlca.sqlcode < 0) sqlprint ( );}
144144
#line 50 "nan_test.pgc"
145145

146-
while (1)
146+
for (loopcount = 0; loopcount < 100; loopcount++)
147147
{
148148
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
149149
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
@@ -227,7 +227,7 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
227227
if (sqlca.sqlcode < 0) sqlprint ( );}
228228
#line 76 "nan_test.pgc"
229229

230-
while (1)
230+
for (loopcount = 0; loopcount < 100; loopcount++)
231231
{
232232
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur1", ECPGt_EOIT,
233233
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+
int loopcount;
271271
char msg[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+
int loopcount;
124124
char msg[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( struct birthinfo ),

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
int main() {
2626
/* exec sql begin declare section */
2727

28-
28+
2929

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

3333
#line 10 "fetch.pgc"
34-
int i , count = 1 ;
34+
int i , 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
int main() {
2626
/* exec sql begin declare section */
2727

28-
28+
2929

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

3333
#line 10 "quote.pgc"
34-
int i ;
34+
int i , 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
@@ -16,7 +16,7 @@ int
1616
main(void)
1717
{
1818
exec sql begin declare section;
19-
int id;
19+
int id, loopcount;
2020
double d;
2121
numeric *num;
2222
char val[16];
@@ -32,7 +32,7 @@ main(void)
3232

3333
exec sql declare cur cursor for select id, d, d from nantest1;
3434
exec sql open cur;
35-
while (1)
35+
for (loopcount = 0; loopcount < 100; loopcount++)
3636
{
3737
exec sql fetch from cur into :id, :d, :val;
3838
if (sqlca.sqlcode)
@@ -48,7 +48,7 @@ main(void)
4848
exec sql close cur;
4949

5050
exec sql open cur;
51-
while (1)
51+
for (loopcount = 0; loopcount < 100; loopcount++)
5252
{
5353
exec sql fetch from cur into :id, :d, :val;
5454
if (sqlca.sqlcode)
@@ -74,7 +74,7 @@ main(void)
7474

7575
exec sql declare cur1 cursor for select id, d, d from nantest2;
7676
exec sql open cur1;
77-
while (1)
77+
for (loopcount = 0; loopcount < 100; loopcount++)
7878
{
7979
exec sql fetch from cur1 into :id, :num, :val;
8080
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/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)