fix(util/sexpr): crash in the sexpr Lua API

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2014-07-07 09:41:14 -07:00
parent 831de22bcd
commit c47d9c01ee
2 changed files with 6 additions and 1 deletions

View file

@ -12,6 +12,7 @@ Author: Leonardo de Moura
#include "util/name.h"
#include "util/escaped.h"
#include "util/buffer.h"
#include "util/sstream.h"
#include "util/object_serializer.h"
#include "util/numerics/mpz.h"
#include "util/numerics/mpq.h"
@ -384,8 +385,11 @@ static sexpr to_sexpr_elem(lua_State * L, int idx) {
return sexpr(to_mpz(L, idx));
} else if (is_mpq(L, idx)) {
return sexpr(to_mpq(L, idx));
} else if (lua_isstring(L, idx)) {
std::string str = lua_tostring(L, idx);
return sexpr(str);
} else {
return sexpr(lua_tostring(L, idx));
throw exception(sstream() << "arg #" << idx << " cannot be casted into an s-expression");
}
}

1
tests/lua/sexpr_bug1.lua Normal file
View file

@ -0,0 +1 @@
check_error(function() print(sexpr(Local("a", Bool))) end)