diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-03-05 12:10:34 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2021-03-05 12:10:34 -0300 |
| commit | f5df7f91f70234850484d26caf24e71e001e5304 (patch) | |
| tree | fe0d12b5b8157b0ad34fc26dd65afa6ff8bb9c56 | |
| parent | e7803f7dbcdc966ab1f9db143424ee811ab1a398 (diff) | |
| download | lua-f5df7f91f70234850484d26caf24e71e001e5304.tar.gz lua-f5df7f91f70234850484d26caf24e71e001e5304.tar.bz2 lua-f5df7f91f70234850484d26caf24e71e001e5304.zip | |
Wrong assertion in 'getbaseline'
The assertion cannot compute 'f->abslineinfo[i]' when the initial
estimate 'i' is -1.
| -rw-r--r-- | ldebug.c | 5 | ||||
| -rw-r--r-- | testes/errors.lua | 8 |
2 files changed, 12 insertions, 1 deletions
| @@ -50,6 +50,8 @@ static int currentpc (CallInfo *ci) { | |||
| 50 | ** an integer division gets the right place. When the source file has | 50 | ** an integer division gets the right place. When the source file has |
| 51 | ** large sequences of empty/comment lines, it may need extra entries, | 51 | ** large sequences of empty/comment lines, it may need extra entries, |
| 52 | ** so the original estimate needs a correction. | 52 | ** so the original estimate needs a correction. |
| 53 | ** If the original estimate is -1, the initial 'if' ensures that the | ||
| 54 | ** 'while' will run at least once. | ||
| 53 | ** The assertion that the estimate is a lower bound for the correct base | 55 | ** The assertion that the estimate is a lower bound for the correct base |
| 54 | ** is valid as long as the debug info has been generated with the same | 56 | ** is valid as long as the debug info has been generated with the same |
| 55 | ** value for MAXIWTHABS or smaller. (Previous releases use a little | 57 | ** value for MAXIWTHABS or smaller. (Previous releases use a little |
| @@ -63,7 +65,8 @@ static int getbaseline (const Proto *f, int pc, int *basepc) { | |||
| 63 | else { | 65 | else { |
| 64 | int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */ | 66 | int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */ |
| 65 | /* estimate must be a lower bond of the correct base */ | 67 | /* estimate must be a lower bond of the correct base */ |
| 66 | lua_assert(i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc); | 68 | lua_assert(i < 0 || |
| 69 | (i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc)); | ||
| 67 | while (i + 1 < f->sizeabslineinfo && pc >= f->abslineinfo[i + 1].pc) | 70 | while (i + 1 < f->sizeabslineinfo && pc >= f->abslineinfo[i + 1].pc) |
| 68 | i++; /* low estimate; adjust it */ | 71 | i++; /* low estimate; adjust it */ |
| 69 | *basepc = f->abslineinfo[i].pc; | 72 | *basepc = f->abslineinfo[i].pc; |
diff --git a/testes/errors.lua b/testes/errors.lua index fd02806e..a3d0676b 100644 --- a/testes/errors.lua +++ b/testes/errors.lua | |||
| @@ -420,6 +420,14 @@ if not b then | |||
| 420 | end | 420 | end |
| 421 | end]], 5) | 421 | end]], 5) |
| 422 | 422 | ||
| 423 | do | ||
| 424 | -- Force a negative estimate for base line. Error in instruction 2 | ||
| 425 | -- (after VARARGPREP, GETGLOBAL), with first absolute line information | ||
| 426 | -- (forced by too many lines) in instruction 0. | ||
| 427 | local s = string.format("%s return __A.x", string.rep("\n", 300)) | ||
| 428 | lineerror(s, 301) | ||
| 429 | end | ||
| 430 | |||
| 423 | 431 | ||
| 424 | if not _soft then | 432 | if not _soft then |
| 425 | -- several tests that exaust the Lua stack | 433 | -- several tests that exaust the Lua stack |
