mirror of
https://github.com/minetest/minetestmapper.git
synced 2024-12-22 22:12:24 +01:00
Fix SEGV after failing to open output file: throw runtime error
The result of opening the file was not checked, resulting in a NULL pointer dereference if it failed.
This commit is contained in:
parent
a15bc30071
commit
d92ef319f1
@ -15,6 +15,8 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include "config.h"
|
||||
#include "PlayerAttributes.h"
|
||||
#include "TileGenerator.h"
|
||||
@ -630,6 +632,11 @@ void TileGenerator::writeImage(const std::string &output)
|
||||
{
|
||||
FILE *out;
|
||||
out = fopen(output.c_str(), "wb");
|
||||
if (!out) {
|
||||
std::ostringstream oss;
|
||||
oss << "Error opening '" << output.c_str() << "': " << std::strerror(errno);
|
||||
throw std::runtime_error(oss.str());
|
||||
}
|
||||
gdImagePng(m_image, out);
|
||||
fclose(out);
|
||||
gdImageDestroy(m_image);
|
||||
|
Loading…
Reference in New Issue
Block a user