diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-03-12 15:51:16 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-03-12 15:51:16 -0300 |
| commit | c931d86e98da320c71da70c16d44aa28e9755520 (patch) | |
| tree | 2c73ee84120f8f7983d883b3f46546e0676f6ba6 /ldo.c | |
| parent | d9e0f64a5de699a620771af299ea22f522c72f19 (diff) | |
| download | lua-c931d86e98da320c71da70c16d44aa28e9755520.tar.gz lua-c931d86e98da320c71da70c16d44aa28e9755520.tar.bz2 lua-c931d86e98da320c71da70c16d44aa28e9755520.zip | |
'luaD_seterrorobj' should not raise errors
This function can be called unprotected, so it should not raise any
kind of errors. (It could raise a memory-allocation error when creating
a message).
Diffstat (limited to 'ldo.c')
| -rw-r--r-- | ldo.c | 36 |
1 files changed, 17 insertions, 19 deletions
| @@ -102,24 +102,13 @@ struct lua_longjmp { | |||
| 102 | 102 | ||
| 103 | 103 | ||
| 104 | void luaD_seterrorobj (lua_State *L, TStatus errcode, StkId oldtop) { | 104 | void luaD_seterrorobj (lua_State *L, TStatus errcode, StkId oldtop) { |
| 105 | switch (errcode) { | 105 | if (errcode == LUA_ERRMEM) { /* memory error? */ |
| 106 | case LUA_ERRMEM: { /* memory error? */ | 106 | setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */ |
| 107 | setsvalue2s(L, oldtop, G(L)->memerrmsg); /* reuse preregistered msg. */ | 107 | } |
| 108 | break; | 108 | else { |
| 109 | } | 109 | lua_assert(errorstatus(errcode)); /* must be a real error */ |
| 110 | case LUA_ERRERR: { | 110 | lua_assert(!ttisnil(s2v(L->top.p - 1))); /* with a non-nil object */ |
| 111 | setsvalue2s(L, oldtop, luaS_newliteral(L, "error in error handling")); | 111 | setobjs2s(L, oldtop, L->top.p - 1); /* move it to 'oldtop' */ |
| 112 | break; | ||
| 113 | } | ||
| 114 | default: { | ||
| 115 | lua_assert(errorstatus(errcode)); /* must be a real error */ | ||
| 116 | if (!ttisnil(s2v(L->top.p - 1))) { /* error object is not nil? */ | ||
| 117 | setobjs2s(L, oldtop, L->top.p - 1); /* move it to 'oldtop' */ | ||
| 118 | } | ||
| 119 | else /* change it to a proper message */ | ||
| 120 | setsvalue2s(L, oldtop, luaS_newliteral(L, "<error object is nil>")); | ||
| 121 | break; | ||
| 122 | } | ||
| 123 | } | 112 | } |
| 124 | L->top.p = oldtop + 1; /* top goes back to old top plus error object */ | 113 | L->top.p = oldtop + 1; /* top goes back to old top plus error object */ |
| 125 | } | 114 | } |
| @@ -190,6 +179,15 @@ TStatus luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud) { | |||
| 190 | #define ERRORSTACKSIZE (MAXSTACK + STACKERRSPACE) | 179 | #define ERRORSTACKSIZE (MAXSTACK + STACKERRSPACE) |
| 191 | 180 | ||
| 192 | 181 | ||
| 182 | /* raise an error while running the message handler */ | ||
| 183 | l_noret luaD_errerr (lua_State *L) { | ||
| 184 | TString *msg = luaS_newliteral(L, "error in error handling"); | ||
| 185 | setsvalue2s(L, L->top.p, msg); | ||
| 186 | L->top.p++; /* assume EXTRA_STACK */ | ||
| 187 | luaD_throw(L, LUA_ERRERR); | ||
| 188 | } | ||
| 189 | |||
| 190 | |||
| 193 | /* | 191 | /* |
| 194 | ** In ISO C, any pointer use after the pointer has been deallocated is | 192 | ** In ISO C, any pointer use after the pointer has been deallocated is |
| 195 | ** undefined behavior. So, before a stack reallocation, all pointers | 193 | ** undefined behavior. So, before a stack reallocation, all pointers |
| @@ -317,7 +315,7 @@ int luaD_growstack (lua_State *L, int n, int raiseerror) { | |||
| 317 | a stack error; cannot grow further than that. */ | 315 | a stack error; cannot grow further than that. */ |
| 318 | lua_assert(stacksize(L) == ERRORSTACKSIZE); | 316 | lua_assert(stacksize(L) == ERRORSTACKSIZE); |
| 319 | if (raiseerror) | 317 | if (raiseerror) |
| 320 | luaD_throw(L, LUA_ERRERR); /* error inside message handler */ | 318 | luaD_errerr(L); /* error inside message handler */ |
| 321 | return 0; /* if not 'raiseerror', just signal it */ | 319 | return 0; /* if not 'raiseerror', just signal it */ |
| 322 | } | 320 | } |
| 323 | else if (n < MAXSTACK) { /* avoids arithmetic overflows */ | 321 | else if (n < MAXSTACK) { /* avoids arithmetic overflows */ |
