base: Do not dereference NULL in CompoundFlag creation
authorAndreas Hansson <andreas.hansson@arm.com>
Wed, 11 Feb 2015 15:23:23 +0000 (10:23 -0500)
committerAndreas Hansson <andreas.hansson@arm.com>
Wed, 11 Feb 2015 15:23:23 +0000 (10:23 -0500)
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.

src/SConscript
src/base/debug.hh

index f85ed7a62e3e5914eb4fc081d864a721c67abb93..cffc4d157fb3c6f6af8d007b0573c83e9ca8b3ca 100755 (executable)
@@ -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)
index 20bf8e76dc1d02b1ba2c201f0749f000b1934af6..5a03574f11a307c1a234870d9684904675c0a609 100644 (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);