cb: Fixed uninitialized memory used for equality check

Fixed by zeroing the memory. A more "c++ correct" approach
may be to add an additional op for equality, and use the "=="
operator on the F type in the generate function. But this adds
the requirement that F supports equality.
pull/5027/head
Christopher Haster 2017-09-05 11:01:27 -05:00
parent 5bddd881e9
commit 382c0381c9
1 changed files with 12 additions and 6 deletions

View File

@ -77,7 +77,7 @@ public:
*/
Callback(R (*func)() = 0) {
if (!func) {
_ops = 0;
memset(this, 0, sizeof(Callback));
} else {
generate(func);
}
@ -590,6 +590,7 @@ private:
MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
"Type F must not exceed the size of the Callback class");
memset(this, 0, sizeof(Callback));
new (this) F(f);
_ops = &ops;
}
@ -651,7 +652,7 @@ public:
*/
Callback(R (*func)(A0) = 0) {
if (!func) {
_ops = 0;
memset(this, 0, sizeof(Callback));
} else {
generate(func);
}
@ -1165,6 +1166,7 @@ private:
MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
"Type F must not exceed the size of the Callback class");
memset(this, 0, sizeof(Callback));
new (this) F(f);
_ops = &ops;
}
@ -1226,7 +1228,7 @@ public:
*/
Callback(R (*func)(A0, A1) = 0) {
if (!func) {
_ops = 0;
memset(this, 0, sizeof(Callback));
} else {
generate(func);
}
@ -1741,6 +1743,7 @@ private:
MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
"Type F must not exceed the size of the Callback class");
memset(this, 0, sizeof(Callback));
new (this) F(f);
_ops = &ops;
}
@ -1802,7 +1805,7 @@ public:
*/
Callback(R (*func)(A0, A1, A2) = 0) {
if (!func) {
_ops = 0;
memset(this, 0, sizeof(Callback));
} else {
generate(func);
}
@ -2318,6 +2321,7 @@ private:
MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
"Type F must not exceed the size of the Callback class");
memset(this, 0, sizeof(Callback));
new (this) F(f);
_ops = &ops;
}
@ -2379,7 +2383,7 @@ public:
*/
Callback(R (*func)(A0, A1, A2, A3) = 0) {
if (!func) {
_ops = 0;
memset(this, 0, sizeof(Callback));
} else {
generate(func);
}
@ -2896,6 +2900,7 @@ private:
MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
"Type F must not exceed the size of the Callback class");
memset(this, 0, sizeof(Callback));
new (this) F(f);
_ops = &ops;
}
@ -2957,7 +2962,7 @@ public:
*/
Callback(R (*func)(A0, A1, A2, A3, A4) = 0) {
if (!func) {
_ops = 0;
memset(this, 0, sizeof(Callback));
} else {
generate(func);
}
@ -3475,6 +3480,7 @@ private:
MBED_STATIC_ASSERT(sizeof(Callback) - sizeof(_ops) >= sizeof(F),
"Type F must not exceed the size of the Callback class");
memset(this, 0, sizeof(Callback));
new (this) F(f);
_ops = &ops;
}