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
int main(void)
{
- $int i = 14;
+ $int i = 14, loopcount;
$decimal j, m, n;
$string c[10];
deccvint(0, &j);
- while (1)
+ for (loopcount = 0; loopcount < 100; loopcount++)
{
$fetch forward c into :i, :j, :c;
if (sqlca.sqlcode == 100) break;
{
#line 14 "test_informix.pgc"
- int i = 14 ;
+ int i = 14 , loopcount ;
#line 14 "test_informix.pgc"
deccvint(0, &j);
- while (1)
+ for (loopcount = 0; loopcount < 100; loopcount++)
{
{ ECPGdo(__LINE__, 1, 1, NULL, 0, ECPGst_normal, "fetch forward c", ECPGt_EOIT,
ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
main(void)
{
/* exec sql begin declare section */
-
+
#line 19 "nan_test.pgc"
- int id ;
+ int id , loopcount ;
#line 20 "nan_test.pgc"
double d ;
if (sqlca.sqlcode < 0) sqlprint ( );}
#line 34 "nan_test.pgc"
- while (1)
+ for (loopcount = 0; loopcount < 100; loopcount++)
{
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
if (sqlca.sqlcode < 0) sqlprint ( );}
#line 50 "nan_test.pgc"
- while (1)
+ for (loopcount = 0; loopcount < 100; loopcount++)
{
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur", ECPGt_EOIT,
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
if (sqlca.sqlcode < 0) sqlprint ( );}
#line 76 "nan_test.pgc"
- while (1)
+ for (loopcount = 0; loopcount < 100; loopcount++)
{
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch from cur1", ECPGt_EOIT,
ECPGt_int,&(id),(long)1,(long)1,sizeof(int),
i = 0;
- while (1)
+ while (i < 100)
{
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur1", ECPGt_EOIT,
ECPGt_int,&(item1),(long)1,(long)1,sizeof(int),
{
MYTYPE *myvar;
MYNULLTYPE *mynullvar;
-
+ int loopcount;
char msg[128];
ECPGdebug(1, stderr);
#line 96 "outofscope.pgc"
- while (1)
+ for (loopcount = 0; loopcount < 100; loopcount++)
{
memset(myvar, 0, sizeof(MYTYPE));
get_record1();
#line 37 "variable.pgc"
-
+ int loopcount;
char msg[128];
ECPGdebug(1, stderr);
p=&personal;
i=&ind_personal;
memset(i, 0, sizeof(ind_personal));
- while (1) {
+ for (loopcount = 0; loopcount < 100; loopcount++) {
strcpy(msg, "fetch");
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch cur", ECPGt_EOIT,
ECPGt_varchar,&(p->name),(long)BUFFERSIZ,(long)-1,sizeof( struct birthinfo ),
int main() {
/* exec sql begin declare section */
-
+
#line 9 "fetch.pgc"
char str [ 25 ] ;
#line 10 "fetch.pgc"
- int i , count = 1 ;
+ int i , count = 1 , loopcount ;
/* exec sql end declare section */
#line 11 "fetch.pgc"
/* exec sql whenever not found break ; */
#line 30 "fetch.pgc"
- while (1) {
+ for (loopcount = 0; loopcount < 100; loopcount++) {
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in C", ECPGt_EOIT,
ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
/* exec sql whenever not found break ; */
#line 48 "fetch.pgc"
- while (1) {
+ for (loopcount = 0; loopcount < 100; loopcount++) {
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch 1 in D", ECPGt_EOIT,
ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
ECPGt_NO_INDICATOR, NULL , 0L, 0L, 0L,
int main() {
/* exec sql begin declare section */
-
+
#line 9 "quote.pgc"
char var [ 25 ] ;
#line 10 "quote.pgc"
- int i ;
+ int i , loopcount ;
/* exec sql end declare section */
#line 11 "quote.pgc"
#line 47 "quote.pgc"
- while (true)
+ for (loopcount = 0; loopcount < 100; loopcount++)
{
{ ECPGdo(__LINE__, 0, 1, NULL, 0, ECPGst_normal, "fetch C", ECPGt_EOIT,
ECPGt_int,&(i),(long)1,(long)1,sizeof(int),
main(void)
{
exec sql begin declare section;
- int id;
+ int id, loopcount;
double d;
numeric *num;
char val[16];
exec sql declare cur cursor for select id, d, d from nantest1;
exec sql open cur;
- while (1)
+ for (loopcount = 0; loopcount < 100; loopcount++)
{
exec sql fetch from cur into :id, :d, :val;
if (sqlca.sqlcode)
exec sql close cur;
exec sql open cur;
- while (1)
+ for (loopcount = 0; loopcount < 100; loopcount++)
{
exec sql fetch from cur into :id, :d, :val;
if (sqlca.sqlcode)
exec sql declare cur1 cursor for select id, d, d from nantest2;
exec sql open cur1;
- while (1)
+ for (loopcount = 0; loopcount < 100; loopcount++)
{
exec sql fetch from cur1 into :id, :num, :val;
if (sqlca.sqlcode)
EXEC SQL WHENEVER NOT FOUND DO BREAK;
i = 0;
- while (1)
+ while (i < 100)
{
EXEC SQL FETCH cur1 INTO :item1:ind1;
printf("item[%d] = %d\n", i, ind1 ? -1 : item1);
{
MYTYPE *myvar;
MYNULLTYPE *mynullvar;
-
+ int loopcount;
char msg[128];
ECPGdebug(1, stderr);
exec sql whenever not found do break;
- while (1)
+ for (loopcount = 0; loopcount < 100; loopcount++)
{
memset(myvar, 0, sizeof(MYTYPE));
get_record1();
exec sql char *married = NULL;
exec sql long ind_married;
exec sql ind children;
-
+ int loopcount;
char msg[128];
ECPGdebug(1, stderr);
p=&personal;
i=&ind_personal;
memset(i, 0, sizeof(ind_personal));
- while (1) {
+ for (loopcount = 0; loopcount < 100; loopcount++) {
strcpy(msg, "fetch");
exec sql fetch cur into :p:i, :married:ind_married, :children.integer:ind_children.smallint;
printf("%8.8s", personal.name.arr);
int main() {
EXEC SQL BEGIN DECLARE SECTION;
char str[25];
- int i, count=1;
+ int i, count=1, loopcount;
EXEC SQL END DECLARE SECTION;
ECPGdebug(1, stderr);
EXEC SQL OPEN C;
EXEC SQL WHENEVER NOT FOUND DO BREAK;
- while (1) {
+ for (loopcount = 0; loopcount < 100; loopcount++) {
EXEC SQL FETCH 1 IN C INTO :i, :str;
printf("%d: %s\n", i, str);
}
EXEC SQL OPEN D using 1;
EXEC SQL WHENEVER NOT FOUND DO BREAK;
- while (1) {
+ for (loopcount = 0; loopcount < 100; loopcount++) {
EXEC SQL FETCH 1 IN D INTO :i, :str;
printf("%d: %s\n", i, str);
}
int main() {
EXEC SQL BEGIN DECLARE SECTION;
char var[25];
- int i;
+ int i, loopcount;
EXEC SQL END DECLARE SECTION;
ECPGdebug(1, stderr);
EXEC SQL WHENEVER NOT FOUND DO BREAK;
- while (true)
+ for (loopcount = 0; loopcount < 100; loopcount++)
{
EXEC SQL FETCH C INTO :i, :var;
printf("value: %d %s\n", i, var);