• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Compiling tfs 0.4 r3884 game.cpp error/warning debian 8

forumek

Member
Joined
Jan 14, 2019
Messages
61
Reaction score
22
Anybody know how to fix it properly? I know I can remove checking from makefile but I would like a proper fix for this also changing bool globalSaveMessage[2]; to [3] in game.h eliminates this but it's just covering this error instead of fixing I guess

C++:
game.cpp: In constructor ‘Game::Game()’:
game.cpp:80:31: error: iteration 2u invokes undefined behavior [-Werror=aggressive-loop-optimizations]
   globalSaveMessage[i] = false;
                               ^
game.cpp:79:2: note: containing loop
  for(int32_t i = 0; i < 3; i++)
  ^
game.cpp:80:22: error: array subscript is above array bounds [-Werror=array-bounds]
   globalSaveMessage[i] = false;
                      ^
game.cpp: In member function ‘void Game::prepareGlobalSave()’:
game.cpp:6256:30: error: array subscript is above array bounds [-Werror=array-bounds]
  else if(!globalSaveMessage[2])
                              ^
game.cpp:6258:22: error: array subscript is above array bounds [-Werror=array-bounds]
   globalSaveMessage[2] = true;
 
So if the size of the array is declared as 2, and you're looping through 3 values (0, 1, 2), you'll get an error message.
If you change the for loop to
C++:
for(int32_t i = 0; i < 2; i++)
it should fix the issue, or (as you said) increase the size of the array.
Or what are you asking here?
 
So if the size of the array is declared as 2, and you're looping through 3 values (0, 1, 2), you'll get an error message.
If you change the for loop to
C++:
for(int32_t i = 0; i < 2; i++)
it should fix the issue, or (as you said) increase the size of the array.
Or what are you asking here?
changing it to 2 fixes loop optimization error but above array bound is still there

so "bool globalSaveMessage[2];" in game.h is an array?

but changing its value to other than 2 won't corrupt global save? it has function under it:
C++:
bool globalSaveMessage[2];

        RefreshTiles refreshTiles;
        Trash trash;

        StageList stages;
        uint32_t lastStageLevel;

        Highscore highscoreStorage[9];
        time_t lastHighscoreCheck;
};
sorry for being a noob
 
I haven't checked game.cpp nor game.h.
They are declarations rather than functions (under globalSaveMessage[2]).
If globalSaveMessage[] is declared as
C++:
bool globalSaveMessage[2]
then it contains 2 booleans.
The for loop, goes through 3 values ([0], [1], [2]), so if there is a usage of all these three values in game.cpp, then you should change the size of the array to 3 instead of 2.

In other words, if you can see that globalSaveMessage[0], globalSaveMessage[1] and globalSaveMessage[2] are used in game.cpp, then you should increase the size of the array to 3 in game.h, like you stated yourself in the first post.
 
lol I thought that
C++:
bool globalSaveMessage[2]
is waiting for this as it has the same value [2]:
C++:
else if(!globalSaveMessage[2])
    {
        globalSaveMessage[2] = true;
        broadcastMessage("Server is going down for a global save in one minute, please logout!", MSG_STATUS_WARNING);
        Scheduler::getInstance().addEvent(createSchedulerTask(60000, boost::bind(&Game::prepareGlobalSave, this)));
    }
and then trigger this:
C++:
 RefreshTiles refreshTiles;
        Trash trash;

        StageList stages;
        uint32_t lastStageLevel;

        Highscore highscoreStorage[9];
        time_t lastHighscoreCheck;

what a moron I am

so after all changing it to 3 bool globalSaveMessage[3] is a proper fix?
 
In my eyes, yes. Ironically, I haven't been involved with TFS in any way, so I might be completely wrong here. I haven't read through the header nor the cpp.

You don't get any error messages by increasing the size to 3 at the beginning. Test it out and see what happens during a save--if you then might get an error message related to the change. If not, and if it's broadcasting correctly, then I'd assume it's working properly.

Leave the thread unsolved, so some one else can perhaps make a good clarification here!
 
In my eyes, yes. Ironically, I haven't been involved with TFS in any way, so I might be completely wrong here. I haven't read through the header nor the cpp.

You don't get any error messages by increasing the size to 3 at the beginning. Test it out and see what happens during a save--if you then might get an error message related to the change. If not, and if it's broadcasting correctly, then I'd assume it's working properly.

Leave the thread unsolved, so some one else can perhaps make a good clarification here!
seems to be working fine ;p
 
Back
Top