|
![]() Click on image to see enlargment |
|
PC-lint/FlexeLint Output | Reference Manual Explanation | Home bug1547.cpp
The evil Dr. Yes invites one James Bond to a New Year's Eve celebration and places before him an enticing array of Martinis. But Bond's spike detector, an elaboration on the code above, is simply not working as expected. Can you spot the flaw? bug1547.cpp lint Output
--- Module: bug1547.cpp (C++)
_
int select = scan( drinks, 100 );
bug1547.cpp 14 Warning 1547: Assignment of array to pointer to base class (arg. no. 1)
bug1547.cpp 14 Warning 1552: Converting pointer to array-of-derived to pointer to base
--- Wrap-up for Module: bug1547.cpp
Info 754: local structure member 'Martini::gin' (line 3, file bug1547.cpp) not referenced
Reference Manual Explanation
1547 Assignment of array to pointer to base class (Context) -- An assignment
from an array of a derived class to a pointer to a base class was detected.
For example:
class B { };
class D : public B {};
D a[10];
B *p = a; // Warning 1547
B *q = &a[0]; // OK
In this example p is being assigned the address of the first element of an
array. This is fraught with danger since access to any element other than
the zeroeth must be considered an error (we presume that B and D actually
have or have the potential to have different sizes).
If you have comments or questions about this bug, please post them to our Discussion Forum |
Previous Bug - Bug #1402 - December 2007