ref: c596dd58c3ccb85a3b1ce75512975d6f38133cd1
parent: 1930f35933654d02234249b8c9b8c0d1c8c9fb6b
author: Tor Andersson <tor@ccxvii.net>
date: Wed Jun 1 11:22:50 EDT 2016
Fix stack trace off-by-one error when skipping the top level entry.
--- a/jserror.c
+++ b/jserror.c
@@ -5,11 +5,13 @@
#define QQ(X) #X
#define Q(X) QQ(X)
-static void jsB_stacktrace(js_State *J, int skip)
+static int jsB_stacktrace(js_State *J, int skip)
{
- int n;
char buf[256];
- for (n = J->tracetop - skip; n > 0; --n) {
+ int n = J->tracetop - skip;
+ if (n <= 0)
+ return 0;
+ for (; n > 0; --n) {
const char *name = J->trace[n].name;
const char *file = J->trace[n].file;
int line = J->trace[n].line;
@@ -24,6 +26,7 @@
if (n < J->tracetop - skip)
js_concat(J);
}
+ return 1;
}
static void Ep_toString(js_State *J)
@@ -55,8 +58,8 @@
js_pushstring(J, js_tostring(J, 1));
js_setproperty(J, -2, "message");
}
- jsB_stacktrace(J, 1);
- js_setproperty(J, -2, "stackTrace");
+ if (jsB_stacktrace(J, 1))
+ js_setproperty(J, -2, "stackTrace");
return 1;
}
@@ -65,8 +68,8 @@
js_pushobject(J, jsV_newobject(J, JS_CERROR, prototype));
js_pushstring(J, message);
js_setproperty(J, -2, "message");
- jsB_stacktrace(J, 0);
- js_setproperty(J, -2, "stackTrace");
+ if (jsB_stacktrace(J, 0))
+ js_setproperty(J, -2, "stackTrace");
}
#define DERROR(name, Name) \