diff --git a/tools/preproc/asm_file.cpp b/tools/preproc/asm_file.cpp index af16e232d..04a7410e0 100644 --- a/tools/preproc/asm_file.cpp +++ b/tools/preproc/asm_file.cpp @@ -41,6 +41,8 @@ AsmFile::AsmFile(std::string filename) : m_filename(filename) if (m_size < 0) FATAL_ERROR("File size of \"%s\" is less than zero.\n", filename.c_str()); + else if (m_size == 0) + return; // Empty file m_buffer = new char[m_size + 1]; @@ -73,7 +75,7 @@ AsmFile::AsmFile(AsmFile&& other) : m_filename(std::move(other.m_filename)) AsmFile::~AsmFile() { - delete[] m_buffer; + if (m_size > 0) delete[] m_buffer; } // Removes comments to simplify further processing. diff --git a/tools/scaninc/asm_file.cpp b/tools/scaninc/asm_file.cpp index 109e604a2..d2cc624ee 100644 --- a/tools/scaninc/asm_file.cpp +++ b/tools/scaninc/asm_file.cpp @@ -36,6 +36,11 @@ AsmFile::AsmFile(std::string path) m_size = std::ftell(fp); + if (m_size < 0) + FATAL_ERROR("File size of \"%s\" is less than zero.\n", path.c_str()); + else if (m_size == 0) + return; // Empty file + m_buffer = new char[m_size]; std::rewind(fp); @@ -51,7 +56,7 @@ AsmFile::AsmFile(std::string path) AsmFile::~AsmFile() { - delete[] m_buffer; + if (m_size > 0) delete[] m_buffer; } IncDirectiveType AsmFile::ReadUntilIncDirective(std::string &path)