mg_schematic: fix leak in lua API, and small cleanup
* Fix leak like behaviour if you load multiple schematics in a loop. * Cleanup check in for, fixing theoretical out of bounds read if Schematic::deserializeFromMts reduced the number of elements in m_nodenames. A != check may need an overflow of the counter before it hits, if origsize is larger than m_nodenames.size(). * Fix function name passed to errorstream: it was wrong. Also use __FUNCTION__ instead of manually using the method name at other places in the function. * Don't shadow the name member in the loop.master
parent
0115da1d63
commit
0aac1b7403
|
@ -267,7 +267,7 @@ bool Schematic::deserializeFromMts(std::istream *is,
|
||||||
//// Read signature
|
//// Read signature
|
||||||
u32 signature = readU32(ss);
|
u32 signature = readU32(ss);
|
||||||
if (signature != MTSCHEM_FILE_SIGNATURE) {
|
if (signature != MTSCHEM_FILE_SIGNATURE) {
|
||||||
errorstream << "Schematic::deserializeFromMts: invalid schematic "
|
errorstream << __FUNCTION__ << ": invalid schematic "
|
||||||
"file" << std::endl;
|
"file" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ bool Schematic::deserializeFromMts(std::istream *is,
|
||||||
//// Read version
|
//// Read version
|
||||||
u16 version = readU16(ss);
|
u16 version = readU16(ss);
|
||||||
if (version > MTSCHEM_FILE_VER_HIGHEST_READ) {
|
if (version > MTSCHEM_FILE_VER_HIGHEST_READ) {
|
||||||
errorstream << "Schematic::deserializeFromMts: unsupported schematic "
|
errorstream << __FUNCTION__ << ": unsupported schematic "
|
||||||
"file version" << std::endl;
|
"file version" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -439,7 +439,7 @@ bool Schematic::loadSchematicFromFile(const std::string &filename,
|
||||||
{
|
{
|
||||||
std::ifstream is(filename.c_str(), std::ios_base::binary);
|
std::ifstream is(filename.c_str(), std::ios_base::binary);
|
||||||
if (!is.good()) {
|
if (!is.good()) {
|
||||||
errorstream << "Schematic::loadSchematicFile: unable to open file '"
|
errorstream << __FUNCTION__ << ": unable to open file '"
|
||||||
<< filename << "'" << std::endl;
|
<< filename << "'" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -448,17 +448,19 @@ bool Schematic::loadSchematicFromFile(const std::string &filename,
|
||||||
if (!deserializeFromMts(&is, &m_nodenames))
|
if (!deserializeFromMts(&is, &m_nodenames))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (replace_names) {
|
|
||||||
for (size_t i = origsize; i != m_nodenames.size(); i++) {
|
|
||||||
std::string &name = m_nodenames[i];
|
|
||||||
StringMap::iterator it = replace_names->find(name);
|
|
||||||
if (it != replace_names->end())
|
|
||||||
name = it->second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
m_nnlistsizes.push_back(m_nodenames.size() - origsize);
|
m_nnlistsizes.push_back(m_nodenames.size() - origsize);
|
||||||
|
|
||||||
|
name = filename;
|
||||||
|
|
||||||
|
if (replace_names) {
|
||||||
|
for (size_t i = origsize; i < m_nodenames.size(); i++) {
|
||||||
|
std::string &node_name = m_nodenames[i];
|
||||||
|
StringMap::iterator it = replace_names->find(node_name);
|
||||||
|
if (it != replace_names->end())
|
||||||
|
node_name = it->second;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ndef)
|
if (ndef)
|
||||||
ndef->pendNodeResolve(this);
|
ndef->pendNodeResolve(this);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue