mirror of https://github.com/OpenTTD/OpenTTD
Fix: GCC warns about possibly uninitialized data in signal.cpp
When compiling with '-Og', GCC warns about variables that are initialized by reference in the condition of a 'while' loop. This commit silences the warning by explicitly initializing the variables in question to their respective 'invalid value' markers, which will most likely be optimized out when the compiler realizes the values are never used.pull/8283/head
parent
a56bf35409
commit
c0bf7cc840
|
@ -268,10 +268,10 @@ static SigFlags ExploreSegment(Owner owner)
|
||||||
{
|
{
|
||||||
SigFlags flags = SF_NONE;
|
SigFlags flags = SF_NONE;
|
||||||
|
|
||||||
TileIndex tile;
|
TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
|
||||||
DiagDirection enterdir;
|
DiagDirection enterdir = INVALID_DIAGDIR;
|
||||||
|
|
||||||
while (_tbdset.Get(&tile, &enterdir)) {
|
while (_tbdset.Get(&tile, &enterdir)) { // tile and enterdir are initialized here, unless I'm mistaken.
|
||||||
TileIndex oldtile = tile; // tile we are leaving
|
TileIndex oldtile = tile; // tile we are leaving
|
||||||
DiagDirection exitdir = enterdir == INVALID_DIAGDIR ? INVALID_DIAGDIR : ReverseDiagDir(enterdir); // expected new exit direction (for straight line)
|
DiagDirection exitdir = enterdir == INVALID_DIAGDIR ? INVALID_DIAGDIR : ReverseDiagDir(enterdir); // expected new exit direction (for straight line)
|
||||||
|
|
||||||
|
@ -407,8 +407,8 @@ static SigFlags ExploreSegment(Owner owner)
|
||||||
*/
|
*/
|
||||||
static void UpdateSignalsAroundSegment(SigFlags flags)
|
static void UpdateSignalsAroundSegment(SigFlags flags)
|
||||||
{
|
{
|
||||||
TileIndex tile;
|
TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
|
||||||
Trackdir trackdir;
|
Trackdir trackdir = INVALID_TRACKDIR;
|
||||||
|
|
||||||
while (_tbuset.Get(&tile, &trackdir)) {
|
while (_tbuset.Get(&tile, &trackdir)) {
|
||||||
assert(HasSignalOnTrackdir(tile, trackdir));
|
assert(HasSignalOnTrackdir(tile, trackdir));
|
||||||
|
@ -474,8 +474,8 @@ static SigSegState UpdateSignalsInBuffer(Owner owner)
|
||||||
bool first = true; // first block?
|
bool first = true; // first block?
|
||||||
SigSegState state = SIGSEG_FREE; // value to return
|
SigSegState state = SIGSEG_FREE; // value to return
|
||||||
|
|
||||||
TileIndex tile;
|
TileIndex tile = INVALID_TILE; // Stop GCC from complaining about a possibly uninitialized variable (issue #8280).
|
||||||
DiagDirection dir;
|
DiagDirection dir = INVALID_DIAGDIR;
|
||||||
|
|
||||||
while (_globset.Get(&tile, &dir)) {
|
while (_globset.Get(&tile, &dir)) {
|
||||||
assert(_tbuset.IsEmpty());
|
assert(_tbuset.IsEmpty());
|
||||||
|
|
Loading…
Reference in New Issue