Commit 936b3617 authored by Aleksy Barcz's avatar Aleksy Barcz

workaround for unitialized memory read on import set

+ if we import a set in draw3 (from .xsd file), defcfg won't set _configId in imported params, leaving it uninitialized and leading to strange errors
+ initialize _configId to invalid value, so at worst it will fail in a more comprehensible way
+ we cannot throw from GetConfigId because of the "Caught unhandled unknown exception; terminating" wx behaviour which hides the place in code from which an exception is thrown. Overriding OnUnhandledException and OnExceptionInMainLoop in szapp (and e.g. calling abort, terminate from there) has no effect.
+ introduced a workaround in a completely different part of code than importing set, as the bug in importing set would be hard to find
parent 3f3418cc
......@@ -840,7 +840,7 @@ public:
void SetParamId(unsigned paramId) { _paramId = paramId; }
unsigned GetConfigId() const { return _configId; }
int GetConfigId();
void SetConfigId(unsigned configId) { _configId = configId; }
......@@ -868,7 +868,7 @@ protected:
unsigned _paramId;
unsigned _configId;
int _configId{-1}; // if left uninitialized, this can lead to ugly errors, so initialize to invalid value
TRaport * _raports; /**< List of raports for param */
TDraw * _draws; /**< List of draws for param */
......
......@@ -750,6 +750,17 @@ std::wstring TParam::GetGlobalName() const {
return sc->GetPrefix() + L":" + _name;
}
int TParam::GetConfigId()
{
if (_configId < 0) {
// _configId should be set, but it's not so let's try to workaround it
if (GetSzarpConfig()) {
SetConfigId(GetSzarpConfig()->GetConfigId());
}
}
return _configId;
}
namespace szarp {
std::wstring substituteWildcards(const std::wstring &name, const std::wstring &ref)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment