diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-05-16 12:39:08 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2007-05-16 12:39:08 -0300 |
commit | 6c0a9a272e3007ffd3a0da82f74525ee756e5f9c (patch) | |
tree | 01ebe421b06aad39a56e6e77ef61707d87528881 | |
parent | 01fa1bc1146f74ba4a9fc7a5dd4c3109d971e257 (diff) | |
download | lua-6c0a9a272e3007ffd3a0da82f74525ee756e5f9c.tar.gz lua-6c0a9a272e3007ffd3a0da82f74525ee756e5f9c.tar.bz2 lua-6c0a9a272e3007ffd3a0da82f74525ee756e5f9c.zip |
assignment of nil to parameter may be optimized away
__concat metamethod converts numbers to strings
loadlib.c should not access Lua internals
code generated for "-nil", "-true", and "-false" is wrong
Count hook may be called without being set
-rw-r--r-- | bugs | 150 |
1 files changed, 145 insertions, 5 deletions
@@ -1294,10 +1294,150 @@ patch = [[ | |||
1294 | } | 1294 | } |
1295 | 1295 | ||
1296 | Bug{ | 1296 | Bug{ |
1297 | what = [[ ]], | 1297 | what = [[assignment of nil to parameter may be optimized away]], |
1298 | report = [[ ]], | 1298 | report = [[Thomas Lauer, on 03/2007]], |
1299 | since = [[ ]], | 1299 | since = [[5.1]], |
1300 | example = [[ ]], | 1300 | example = [[ |
1301 | patch = [[ ]], | 1301 | function f (a) |
1302 | a=nil | ||
1303 | return a | ||
1304 | end | ||
1305 | |||
1306 | print(f("test")) | ||
1307 | ]], | ||
1308 | patch = [[ | ||
1309 | *lcode.c: | ||
1310 | @@ -35,16 +35,20 @@ | ||
1311 | void luaK_nil (FuncState *fs, int from, int n) { | ||
1312 | Instruction *previous; | ||
1313 | if (fs->pc > fs->lasttarget) { /* no jumps to current position? */ | ||
1314 | - if (fs->pc == 0) /* function start? */ | ||
1315 | - return; /* positions are already clean */ | ||
1316 | - previous = &fs->f->code[fs->pc-1]; | ||
1317 | - if (GET_OPCODE(*previous) == OP_LOADNIL) { | ||
1318 | - int pfrom = GETARG_A(*previous); | ||
1319 | - int pto = GETARG_B(*previous); | ||
1320 | - if (pfrom <= from && from <= pto+1) { /* can connect both? */ | ||
1321 | - if (from+n-1 > pto) | ||
1322 | - SETARG_B(*previous, from+n-1); | ||
1323 | - return; | ||
1324 | + if (fs->pc == 0) { /* function start? */ | ||
1325 | + if (from >= fs->nactvar) | ||
1326 | + return; /* positions are already clean */ | ||
1327 | + } | ||
1328 | + else { | ||
1329 | + previous = &fs->f->code[fs->pc-1]; | ||
1330 | + if (GET_OPCODE(*previous) == OP_LOADNIL) { | ||
1331 | + int pfrom = GETARG_A(*previous); | ||
1332 | + int pto = GETARG_B(*previous); | ||
1333 | + if (pfrom <= from && from <= pto+1) { /* can connect both? */ | ||
1334 | + if (from+n-1 > pto) | ||
1335 | + SETARG_B(*previous, from+n-1); | ||
1336 | + return; | ||
1337 | + } | ||
1338 | } | ||
1339 | } | ||
1340 | } | ||
1341 | ]], | ||
1342 | } | ||
1343 | |||
1344 | |||
1345 | Bug{ | ||
1346 | what = [[__concat metamethod converts numbers to strings]], | ||
1347 | report = [[Paul Winwood, on 12/2006]], | ||
1348 | since = [[5.0]], | ||
1349 | example = [[ | ||
1350 | a = {} | ||
1351 | setmetatable(a, {__concat = function (a,b) print(type(a), type(b)) end}) | ||
1352 | a = 4 .. a | ||
1353 | ]], | ||
1354 | patch = [[ | ||
1355 | *lvm.c: | ||
1356 | @@ -281,10 +281,12 @@ | ||
1357 | do { | ||
1358 | StkId top = L->base + last + 1; | ||
1359 | int n = 2; /* number of elements handled in this pass (at least 2) */ | ||
1360 | - if (!tostring(L, top-2) || !tostring(L, top-1)) { | ||
1361 | + if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) { | ||
1362 | if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT)) | ||
1363 | luaG_concaterror(L, top-2, top-1); | ||
1364 | - } else if (tsvalue(top-1)->len > 0) { /* if len=0, do nothing */ | ||
1365 | + } else if (tsvalue(top-1)->len == 0) /* second op is empty? */ | ||
1366 | + (void)tostring(L, top - 2); /* result is first op (as string) */ | ||
1367 | + else { | ||
1368 | /* at least two string values; get as many as possible */ | ||
1369 | size_t tl = tsvalue(top-1)->len; | ||
1370 | char *buffer; | ||
1371 | ]], | ||
1302 | } | 1372 | } |
1303 | 1373 | ||
1374 | |||
1375 | Bug{ | ||
1376 | what = [[As a library, loadlib.c should not access Lua internals | ||
1377 | (via lobject.h)]], | ||
1378 | report = [[Jérôme Vuarand, on 03/2007]], | ||
1379 | since = [[5.0 (at least)]], | ||
1380 | example = [[the bug has no effect on external behavior]], | ||
1381 | patch = [[remove the '#include "lobject.h" and use | ||
1382 | 'lua_pushfstring' instead of 'luaO_pushfstring']], | ||
1383 | } | ||
1384 | |||
1385 | Bug{ | ||
1386 | what = [[Lua may close standard files, | ||
1387 | which then may be used by C]], | ||
1388 | report = [[David Manura/Ross Berteig, on 04/2007]], | ||
1389 | since = [[ ]], | ||
1390 | example = [[ | ||
1391 | io.close(io.stderr) | ||
1392 | -- in some systems, following attempts to write to 'stderr' may crash | ||
1393 | a = a + 1 | ||
1394 | ]], | ||
1395 | patch = [[ | ||
1396 | ]], | ||
1397 | } | ||
1398 | |||
1399 | Bug{ | ||
1400 | what = [[code generated for "-nil", "-true", and "-false" is wrong]], | ||
1401 | report = [[David Manura/Rici Lake, on 04/2007]], | ||
1402 | since = [[5.1]], | ||
1403 | example = [[print(-nil)]], | ||
1404 | patch = [[ | ||
1405 | lcode.c: | ||
1406 | @@ -699,7 +699,7 @@ | ||
1407 | e2.t = e2.f = NO_JUMP; e2.k = VKNUM; e2.u.nval = 0; | ||
1408 | switch (op) { | ||
1409 | case OPR_MINUS: { | ||
1410 | - if (e->k == VK) | ||
1411 | + if (!isnumeral(e)) | ||
1412 | luaK_exp2anyreg(fs, e); /* cannot operate on non-numeric constants */ | ||
1413 | codearith(fs, OP_UNM, e, &e2); | ||
1414 | break; | ||
1415 | ]], | ||
1416 | } | ||
1417 | |||
1418 | Bug{ | ||
1419 | what = [[Count hook may be called without being set.]], | ||
1420 | report = [[Mike Pall, on May 2007]], | ||
1421 | since = [[?]], | ||
1422 | example = [[ ]], | ||
1423 | patch = [[ | ||
1424 | lvm.c: | ||
1425 | @@ -61,7 +61,7 @@ | ||
1426 | lu_byte mask = L->hookmask; | ||
1427 | const Instruction *oldpc = L->savedpc; | ||
1428 | L->savedpc = pc; | ||
1429 | - if (mask > LUA_MASKLINE) { /* instruction-hook set? */ | ||
1430 | + if ((mask & LUA_MASKCOUNT) && L->hookcount == 0) { | ||
1431 | if (L->hookcount == 0) { | ||
1432 | resethookcount(L); | ||
1433 | luaD_callhook(L, LUA_HOOKCOUNT, -1); | ||
1434 | ]], | ||
1435 | } | ||
1436 | |||
1437 | Bug{ | ||
1438 | what = [[ ]], | ||
1439 | report = [[ , on ]], | ||
1440 | since = [[i ]], | ||
1441 | example = [[ ]], | ||
1442 | patch = [[ ]], | ||
1443 | } | ||