From e99d65bc856f7f4770f9633a146e8caf7b6a3016 Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Tue, 27 Oct 2015 15:36:01 +0100 Subject: [PATCH] Fix various SEGV See GH #87. Fixes Function()() (empty closure or method), Error() (empty error message), Lobby cmp 0 (compare with Lobby is always 1, unless with Lobby which is 0). string of Compiled() (proto_string) not yet fixed --- core/internal.c | 6 ++++++ core/primitive.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/core/internal.c b/core/internal.c index 1a6c42e5..49c06b89 100644 --- a/core/internal.c +++ b/core/internal.c @@ -142,6 +142,10 @@ PN potion_delegated(Potion *P, PN closure, PN self) { PN potion_call(Potion *P, PN cl, PN_SIZE argc, PN * volatile argv) { vPN(Closure) c = PN_CLOSURE(cl); + if (!c || !c->method) { + //return PN_NIL; + return potion_error(P, PN_STR("Error: Empty closure or method"), 0, 0, 0); + } switch (argc) { case 0: return c->method(P, cl, cl); @@ -240,6 +244,8 @@ PN potion_error(Potion *P, PN msg, long lineno, long charno, PN excerpt) { PN potion_error_string(Potion *P, PN cl, PN self) { vPN(Error) e = (struct PNError *)self; + if (!e || !e->message) + return potion_str_format(P, "** Error\n"); if (e->excerpt == PN_NIL) return potion_str_format(P, "** %s\n", PN_STR_PTR(e->message)); return potion_str_format(P, "** %s\n" diff --git a/core/primitive.c b/core/primitive.c index 9d3310f7..ca4db7fa 100644 --- a/core/primitive.c +++ b/core/primitive.c @@ -24,7 +24,9 @@ static PN potion_any_is_nil(Potion *P, PN closure, PN self) { \param value PN \return PNInteger -1 if less, 0 if equal or 1 if greater */ PN potion_any_cmp(Potion *P, PN cl, PN self, PN value) { - return potion_send(self, PN_cmp, value); + return (self == P->lobby) + ? ((value == P->lobby) ? PN_NUM(0) : PN_NUM(1)) // Lobby is greater than anything + : potion_send(self, PN_cmp, value); } /** memberof NilKind "cmp" method. nil is 0 or "" or FALSE as cmp context