commit f5df7f91f70234850484d26caf24e71e001e5304
parent e7803f7dbcdc966ab1f9db143424ee811ab1a398
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Fri, 5 Mar 2021 12:10:07 -0300
Wrong assertion in 'getbaseline'
The assertion cannot compute 'f->abslineinfo[i]' when the initial
estimate 'i' is -1.
Diffstat:
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/ldebug.c b/ldebug.c
@@ -50,6 +50,8 @@ static int currentpc (CallInfo *ci) {
** an integer division gets the right place. When the source file has
** large sequences of empty/comment lines, it may need extra entries,
** so the original estimate needs a correction.
+** If the original estimate is -1, the initial 'if' ensures that the
+** 'while' will run at least once.
** The assertion that the estimate is a lower bound for the correct base
** is valid as long as the debug info has been generated with the same
** value for MAXIWTHABS or smaller. (Previous releases use a little
@@ -63,7 +65,8 @@ static int getbaseline (const Proto *f, int pc, int *basepc) {
else {
int i = cast_uint(pc) / MAXIWTHABS - 1; /* get an estimate */
/* estimate must be a lower bond of the correct base */
- lua_assert(i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc);
+ lua_assert(i < 0 ||
+ (i < f->sizeabslineinfo && f->abslineinfo[i].pc <= pc));
while (i + 1 < f->sizeabslineinfo && pc >= f->abslineinfo[i + 1].pc)
i++; /* low estimate; adjust it */
*basepc = f->abslineinfo[i].pc;
diff --git a/testes/errors.lua b/testes/errors.lua
@@ -420,6 +420,14 @@ if not b then
end
end]], 5)
+do
+ -- Force a negative estimate for base line. Error in instruction 2
+ -- (after VARARGPREP, GETGLOBAL), with first absolute line information
+ -- (forced by too many lines) in instruction 0.
+ local s = string.format("%s return __A.x", string.rep("\n", 300))
+ lineerror(s, 301)
+end
+
if not _soft then
-- several tests that exaust the Lua stack