You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello and thank you for the awesome piece of code that sol is!
I was evaluating what kind of safety net needs to be put around sol in the context of my application, and I found that the following example of const-related undefined behavior isn't caught by sol:
#include<sol/sol.hpp>voidf(int *x)
{
*x = 5;
}
intmain()
{
sol::state lua;
lua["f"] = f;
constint x = 0;
auto result = lua["f"](&x); // f(&x) is incorrect and casting the const away is undefined behaviorreturn result.valid();
}
I tested this with GCC 11.2.0 and sol 4.0.0-alpha, compiling with:
g++ -I sol2/ -o test test.cpp -llua
With this compiler on my system I get result.valid() == true. In the debugger I can see that f is executed. Of course this is undefined behavior so YMMV.
Can sol prevent this? (I understand that Lua itself has no cv-qualifiers so this might not be so trivial.) I found no configuration option by the name CONST; -DSOL_ALL_SAFETIES_ON=1 did not help either. If nothing can be done in sol, I suppose I'll want to override sol_lua_push to prevent accidentally pushing any const pointer or reference, but even that wouldn't solve every possible case (I can get a std::function<void(const int*)> out of lua["f"]).
The text was updated successfully, but these errors were encountered:
Hello and thank you for the awesome piece of code that
sol
is!I was evaluating what kind of safety net needs to be put around
sol
in the context of my application, and I found that the following example ofconst
-related undefined behavior isn't caught bysol
:I tested this with GCC 11.2.0 and
sol
4.0.0-alpha, compiling with:With this compiler on my system I get
result.valid() == true
. In the debugger I can see thatf
is executed. Of course this is undefined behavior so YMMV.Can
sol
prevent this? (I understand that Lua itself has no cv-qualifiers so this might not be so trivial.) I found no configuration option by the nameCONST
;-DSOL_ALL_SAFETIES_ON=1
did not help either. If nothing can be done insol
, I suppose I'll want to overridesol_lua_push
to prevent accidentally pushing anyconst
pointer or reference, but even that wouldn't solve every possible case (I can get astd::function<void(const int*)>
out oflua["f"]
).The text was updated successfully, but these errors were encountered: