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.master
parent
4f504a6357
commit
18303eda33
|
@ -15,6 +15,8 @@
|
|||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include "config.h"
|
||||
#include "PlayerAttributes.h"
|
||||
#include "TileGenerator.h"
|
||||
|
@ -629,6 +631,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