Tcl Source Code

Check-in [7a737d57dd]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix more problems with break and continue in for-step clauses.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | Coverity CID 1251203
Files: files | file ages | folders
SHA1: 7a737d57dda819cb55d0d6e6111e7d2c5a6252fe
User & Date: dkf 2015-08-02 12:22:02
Context
2015-08-02
16:17
And another problem with continue in for-step clauses, this time a problem in how TEBC handled an ed... check-in: f489f70210 user: dkf tags: Coverity CID 1251203
12:22
Fix more problems with break and continue in for-step clauses. check-in: 7a737d57dd user: dkf tags: Coverity CID 1251203
2015-08-01
19:37
Fix Coverity CID 1251203: break vs continue in for-step clause check-in: 3481934110 user: dkf tags: Coverity CID 1251203
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to generic/tclCompile.c.

4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105











4106
4107
4108
4109
4110
4111
4112
     * special handling exception range (so that we can correctly unwind the
     * stack).
     *
     * These must be done separately; they can be different (especially for
     * calls from inside a [for] increment clause).
     */

    rangePtr = TclGetInnermostExceptionRange(envPtr, TCL_BREAK, &auxBreakPtr);
    if (rangePtr == NULL || rangePtr->type != LOOP_EXCEPTION_RANGE) {
	auxBreakPtr = NULL;
    } else if (auxBreakPtr->stackDepth == envPtr->currStackDepth-wordCount
	    && auxBreakPtr->expandTarget == envPtr->expandCount-expandCount) {
	auxBreakPtr = NULL;
    } else {
	breakRange = auxBreakPtr - envPtr->exceptAuxArrayPtr;
    }

    rangePtr = TclGetInnermostExceptionRange(envPtr, TCL_CONTINUE,
	    &auxContinuePtr);
    if (rangePtr == NULL || rangePtr->type != LOOP_EXCEPTION_RANGE) {
	auxContinuePtr = NULL;
    } else if (auxContinuePtr->stackDepth == envPtr->currStackDepth-wordCount
	    && auxContinuePtr->expandTarget == envPtr->expandCount-expandCount) {
	auxContinuePtr = NULL;
    } else {
	continueRange = auxContinuePtr - envPtr->exceptAuxArrayPtr;
    }












    if (auxBreakPtr != NULL || auxContinuePtr != NULL) {
	loopRange = TclCreateExceptRange(LOOP_EXCEPTION_RANGE, envPtr);
	ExceptionRangeStarts(envPtr, loopRange);
    }

    /*







<
<
<
<
<
<
<
<
<
<










>
>
>
>
>
>
>
>
>
>
>







4079
4080
4081
4082
4083
4084
4085










4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
     * special handling exception range (so that we can correctly unwind the
     * stack).
     *
     * These must be done separately; they can be different (especially for
     * calls from inside a [for] increment clause).
     */











    rangePtr = TclGetInnermostExceptionRange(envPtr, TCL_CONTINUE,
	    &auxContinuePtr);
    if (rangePtr == NULL || rangePtr->type != LOOP_EXCEPTION_RANGE) {
	auxContinuePtr = NULL;
    } else if (auxContinuePtr->stackDepth == envPtr->currStackDepth-wordCount
	    && auxContinuePtr->expandTarget == envPtr->expandCount-expandCount) {
	auxContinuePtr = NULL;
    } else {
	continueRange = auxContinuePtr - envPtr->exceptAuxArrayPtr;
    }

    rangePtr = TclGetInnermostExceptionRange(envPtr, TCL_BREAK, &auxBreakPtr);
    if (rangePtr == NULL || rangePtr->type != LOOP_EXCEPTION_RANGE) {
	auxBreakPtr = NULL;
    } else if (auxContinuePtr == NULL
	    && auxBreakPtr->stackDepth == envPtr->currStackDepth-wordCount
	    && auxBreakPtr->expandTarget == envPtr->expandCount-expandCount) {
	auxBreakPtr = NULL;
    } else {
	breakRange = auxBreakPtr - envPtr->exceptAuxArrayPtr;
    }

    if (auxBreakPtr != NULL || auxContinuePtr != NULL) {
	loopRange = TclCreateExceptRange(LOOP_EXCEPTION_RANGE, envPtr);
	ExceptionRangeStarts(envPtr, loopRange);
    }

    /*

Changes to tests/for.test.

1216
1217
1218
1219
1220
1221
1222






























































































































1223
1224
1225
1226
1227
1228
1229
	for {set k 0} {$k < 3} {incr k} {
	    set j 0
	    list a [\
	    for {set i 0} {$i < 5} {incr i;list a [eval continue]} {
		incr j
	    }]
	    incr i






























































































































	}
	list $i $j $k
    }}
} {1 1 3}

# cleanup
::tcltest::cleanupTests







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
	for {set k 0} {$k < 3} {incr k} {
	    set j 0
	    list a [\
	    for {set i 0} {$i < 5} {incr i;list a [eval continue]} {
		incr j
	    }]
	    incr i
	}
	list $i $j $k
    }}
} {1 1 3}
test for-8.3 {break in for-step clause} {
    apply {{} {
	for {set k 0} {$k < 3} {incr k} {
	    set j 0
	    list a [\
	    for {set i 0} {$i < 5} {incr i; break} {
		incr j
	    }]
	    incr i
	}
	list $i $j $k
    }}
} {2 1 3}
test for-8.4 {continue in for-step clause} {
    apply {{} {
	for {set k 0} {$k < 3} {incr k} {
	    set j 0
	    list a [\
	    for {set i 0} {$i < 5} {incr i; continue} {
		incr j
	    }]
	    incr i
	}
	list $i $j $k
    }}
} {1 1 3}
test for-8.5 {break in for-step clause} {
    apply {{} {
	for {set k 0} {$k < 3} {incr k} {
	    set j 0
	    list a [\
	    for {set i 0} {$i < 5} {incr i; list a [break]} {
		incr j
	    }]
	    incr i
	}
	list $i $j $k
    }}
} {2 1 3}
test for-8.6 {continue in for-step clause} {
    apply {{} {
	for {set k 0} {$k < 3} {incr k} {
	    set j 0
	    list a [\
	    for {set i 0} {$i < 5} {incr i; list a [continue]} {
		incr j
	    }]
	    incr i
	}
	list $i $j $k
    }}
} {1 1 3}
test for-8.7 {break in for-step clause} {
    apply {{} {
	for {set k 0} {$k < 3} {incr k} {
	    set j 0
	    list a [\
	    for {set i 0} {$i < 5} {incr i;eval break} {
		incr j
	    }]
	    incr i
	}
	list $i $j $k
    }}
} {2 1 3}
test for-8.8 {continue in for-step clause} {
    apply {{} {
	for {set k 0} {$k < 3} {incr k} {
	    set j 0
	    list a [\
	    for {set i 0} {$i < 5} {incr i;eval continue} {
		incr j
	    }]
	    incr i
	}
	list $i $j $k
    }}
} {1 1 3}
test for-8.9 {break in for-step clause} {
    apply {{} {
	for {set k 0} {$k < 3} {incr k} {
	    set j 0
	    for {set i 0} {$i < 5} {incr i;eval break} {
		incr j
	    }
	    incr i
	}
	list $i $j $k
    }}
} {2 1 3}
test for-8.10 {continue in for-step clause} knownBug {
    apply {{} {
	for {set k 0} {$k < 3} {incr k} {
	    set j 0
	    for {set i 0} {$i < 5} {incr i;eval continue} {
		incr j
	    }
	    incr i
	}
	list $i $j $k
    }}
} {1 1 3}
test for-8.11 {break in for-step clause} {
    apply {{} {
	for {set k 0} {$k < 3} {incr k} {
	    set j 0
	    for {set i 0} {$i < 5} {incr i;break} {
		incr j
	    }
	    incr i
	}
	list $i $j $k
    }}
} {2 1 3}
test for-8.12 {continue in for-step clause} {
    apply {{} {
	for {set k 0} {$k < 3} {incr k} {
	    set j 0
	    for {set i 0} {$i < 5} {incr i;continue} {
		incr j
	    }
	    incr i
	}
	list $i $j $k
    }}
} {1 1 3}

# cleanup
::tcltest::cleanupTests