From d52534954931c6b7243ea1b8baff13f0a581cde0 Mon Sep 17 00:00:00 2001 From: Bart van Strien Date: Thu, 12 Jan 2012 11:30:09 +0100 Subject: [PATCH] Fix usage of a string past its lifetime, and set a default type for encode --- src/modules/image/wrap_ImageData.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/image/wrap_ImageData.cpp b/src/modules/image/wrap_ImageData.cpp index 9bb9bd551..99c4c4095 100644 --- a/src/modules/image/wrap_ImageData.cpp +++ b/src/modules/image/wrap_ImageData.cpp @@ -149,16 +149,18 @@ namespace image if (lua_isstring(L, 2)) luax_convobj(L, 2, "filesystem", "newFile"); love::filesystem::File * file = luax_checktype(L, 2, "File", FILESYSTEM_FILE_T); + std::string ext; const char * fmt; if (lua_isnoneornil(L, 3)) { - fmt = file->getExtension().c_str(); + ext = file->getExtension(); + fmt = ext.c_str(); } else { fmt = luaL_checkstring(L, 3); } - ImageData::Format format; + ImageData::Format format = ImageData::FORMAT_PNG; ImageData::getConstant(fmt, format); try {