operator [0] on empty vector crashes

Issue #763
This commit is contained in:
Flyinghead 2022-10-04 18:21:10 +02:00
parent b821ece052
commit 7da0549b8c
5 changed files with 15 additions and 6 deletions

View File

@ -295,7 +295,10 @@ public:
{
verify(!Sh4cntx.CpuRunning);
size = stack.size() * 8;
return (const u32 *)&stack[0];
if (!stack.empty())
return (const u32 *)&stack[0];
else
return nullptr;
}
void subroutineCall()

View File

@ -88,7 +88,7 @@ json TheGamesDb::httpGet(const std::string& url)
blackoutPeriod = os_GetSeconds() + 60.0;
else if (!success)
blackoutPeriod = os_GetSeconds() + 1.0;
if (!success)
if (!success || receivedData.empty())
throw std::runtime_error("http error");
std::string content((const char *)&receivedData[0], receivedData.size());

View File

@ -120,7 +120,7 @@ static bool pvrParse(const u8 *data, u32 len, u32& width, u32& height, std::vect
WARN_LOG(COMMON, "Unsupported PVR pixel type: %d", pixelFormat);
return false;
}
DEBUG_LOG(COMMON, "PVR file: size %d pixelFmt %d imgType %d w %d h %d\n", size, pixelFormat, imgType, width, height);
DEBUG_LOG(COMMON, "PVR file: size %d pixelFmt %d imgType %d w %d h %d", size, pixelFormat, imgType, width, height);
u32 texU = 3;
while (1u << texU < width)
texU++;

View File

@ -33,12 +33,17 @@ bool Scraper::downloadImage(const std::string& url, const std::string& localName
std::string contentType;
if (!http::success(http::get(url, content, contentType)))
{
WARN_LOG(COMMON, "download_image http error: %s", url.c_str());
WARN_LOG(COMMON, "downloadImage http error: %s", url.c_str());
return false;
}
if (contentType.substr(0, 6) != "image/")
{
WARN_LOG(COMMON, "download_image bad content type %s", contentType.c_str());
WARN_LOG(COMMON, "downloadImage bad content type %s", contentType.c_str());
return false;
}
if (content.empty())
{
WARN_LOG(COMMON, "downloadImage: empty content");
return false;
}
FILE *f = nowide::fopen(localName.c_str(), "wb");

View File

@ -68,7 +68,8 @@ OpenGLDriver::~OpenGLDriver()
texIds.push_back((GLuint)(uintptr_t)crosshairTexId);
for (const auto& it : textures)
texIds.push_back((GLuint)(uintptr_t)it.second);
glcache.DeleteTextures(texIds.size(), &texIds[0]);
if (!texIds.empty())
glcache.DeleteTextures(texIds.size(), &texIds[0]);
ImGui_ImplOpenGL3_Shutdown();
}