mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Fixed undefined behaviour when love exceptions are converted into Lua errors (resolves issue #729)
This commit is contained in:
@@ -42,9 +42,9 @@ int w_newRasterizer(lua_State *L)
|
||||
if (lua_isstring(L, 1) || luax_istype(L, 1, FILESYSTEM_FILE_T))
|
||||
luax_convobj(L, 1, "filesystem", "newFileData");
|
||||
|
||||
Rasterizer *t = NULL;
|
||||
try
|
||||
{
|
||||
Rasterizer *t = 0;
|
||||
|
||||
EXCEPT_GUARD(
|
||||
if (luax_istype(L, 1, IMAGE_IMAGE_DATA_T))
|
||||
{
|
||||
love::image::ImageData *d = luax_checktype<love::image::ImageData>(L, 1, "ImageData", IMAGE_IMAGE_DATA_T);
|
||||
@@ -58,11 +58,7 @@ int w_newRasterizer(lua_State *L)
|
||||
int size = luaL_checkint(L, 2);
|
||||
t = instance->newRasterizer(d, size);
|
||||
}
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
)
|
||||
|
||||
luax_pushtype(L, "Rasterizer", FONT_RASTERIZER_T, t);
|
||||
return 1;
|
||||
@@ -77,14 +73,8 @@ int w_newGlyphData(lua_State *L)
|
||||
if (lua_type(L, 2) == LUA_TSTRING)
|
||||
{
|
||||
std::string glyph = luax_checkstring(L, 2);
|
||||
try
|
||||
{
|
||||
t = instance->newGlyphData(r, glyph);
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
|
||||
EXCEPT_GUARD(t = instance->newGlyphData(r, glyph);)
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -115,14 +105,7 @@ extern "C" int luaopen_love_font(lua_State *L)
|
||||
{
|
||||
if (instance == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
instance = new Font();
|
||||
}
|
||||
catch(Exception &e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
EXCEPT_GUARD(instance = new Font();)
|
||||
}
|
||||
else
|
||||
instance->retain();
|
||||
|
||||
@@ -63,14 +63,8 @@ int w_GlyphData_getGlyph(lua_State *L)
|
||||
int w_GlyphData_getGlyphString(lua_State *L)
|
||||
{
|
||||
GlyphData *t = luax_checkglyphdata(L, 1);
|
||||
try
|
||||
{
|
||||
luax_pushstring(L, t->getGlyphString());
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
|
||||
EXCEPT_GUARD(luax_pushstring(L, t->getGlyphString());)
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,8 +72,7 @@ int w_Rasterizer_getGlyphData(lua_State *L)
|
||||
Rasterizer *t = luax_checkrasterizer(L, 1);
|
||||
GlyphData *g = 0;
|
||||
|
||||
try
|
||||
{
|
||||
EXCEPT_GUARD(
|
||||
// getGlyphData accepts a unicode character or a codepoint number.
|
||||
if (lua_type(L, 2) == LUA_TSTRING)
|
||||
{
|
||||
@@ -85,11 +84,7 @@ int w_Rasterizer_getGlyphData(lua_State *L)
|
||||
uint32 glyph = (uint32) luaL_checknumber(L, 2);
|
||||
g = t->getGlyphData(glyph);
|
||||
}
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
)
|
||||
|
||||
luax_pushtype(L, "GlyphData", FONT_GLYPH_DATA_T, g);
|
||||
return 1;
|
||||
@@ -108,17 +103,12 @@ int w_Rasterizer_hasGlyph(lua_State *L)
|
||||
|
||||
bool hasglyph = false;
|
||||
|
||||
try
|
||||
{
|
||||
EXCEPT_GUARD(
|
||||
if (lua_type(L, 2) == LUA_TSTRING)
|
||||
hasglyph = t->hasGlyph(luax_checkstring(L, 2));
|
||||
else
|
||||
hasglyph = t->hasGlyph((uint32) luaL_checknumber(L, 2));
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luaL_error(L, "%s", e.what());
|
||||
}
|
||||
)
|
||||
|
||||
luax_pushboolean(L, hasglyph);
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user