base: Do not dereference NULL in CompoundFlag creation

This patch fixes the CompoundFlag constructor, ensuring that it does
not dereference NULL. Doing so has undefined behaviuor, and both clang
and gcc's undefined-behaviour sanitiser was rather unhappy.
This commit is contained in:
Andreas Hansson 2015-02-11 10:23:23 -05:00
parent 431a6d708b
commit c9b8616c51
2 changed files with 15 additions and 15 deletions

View file

@ -852,9 +852,9 @@ namespace Debug {
last = len(compound) - 1
for i,flag in enumerate(compound):
if i != last:
comp_code('$flag,')
comp_code('&$flag,')
else:
comp_code('$flag);')
comp_code('&$flag);')
comp_code.dedent()
code.append(comp_code)

View file

@ -81,24 +81,24 @@ class CompoundFlag : public SimpleFlag
{
protected:
void
addFlag(Flag &f)
addFlag(Flag *f)
{
if (&f != NULL)
_kids.push_back(&f);
if (f != nullptr)
_kids.push_back(f);
}
public:
CompoundFlag(const char *name, const char *desc,
Flag &f00 = *(Flag *)0, Flag &f01 = *(Flag *)0,
Flag &f02 = *(Flag *)0, Flag &f03 = *(Flag *)0,
Flag &f04 = *(Flag *)0, Flag &f05 = *(Flag *)0,
Flag &f06 = *(Flag *)0, Flag &f07 = *(Flag *)0,
Flag &f08 = *(Flag *)0, Flag &f09 = *(Flag *)0,
Flag &f10 = *(Flag *)0, Flag &f11 = *(Flag *)0,
Flag &f12 = *(Flag *)0, Flag &f13 = *(Flag *)0,
Flag &f14 = *(Flag *)0, Flag &f15 = *(Flag *)0,
Flag &f16 = *(Flag *)0, Flag &f17 = *(Flag *)0,
Flag &f18 = *(Flag *)0, Flag &f19 = *(Flag *)0)
Flag *f00 = nullptr, Flag *f01 = nullptr,
Flag *f02 = nullptr, Flag *f03 = nullptr,
Flag *f04 = nullptr, Flag *f05 = nullptr,
Flag *f06 = nullptr, Flag *f07 = nullptr,
Flag *f08 = nullptr, Flag *f09 = nullptr,
Flag *f10 = nullptr, Flag *f11 = nullptr,
Flag *f12 = nullptr, Flag *f13 = nullptr,
Flag *f14 = nullptr, Flag *f15 = nullptr,
Flag *f16 = nullptr, Flag *f17 = nullptr,
Flag *f18 = nullptr, Flag *f19 = nullptr)
: SimpleFlag(name, desc)
{
addFlag(f00); addFlag(f01); addFlag(f02); addFlag(f03); addFlag(f04);