commit 02428d87
Uses some more secure function in old C strings
Changed files
| M | source/code/highscore.cpp before |
| M | source/code/highscore.h before |
| M | source/code/main.cpp before |
diff --git a/source/code/highscore.cpp b/source/code/highscore.cpp
index de94965..cf13be1 100644
--- a/source/code/highscore.cpp
+++ b/source/code/highscore.cpp
@@ -103,6 +103,6 @@ int Highscore::getScoreNumber(int room) {
return tabel[room].score;
}
-char* Highscore::getScoreName(int room) {
+const char* Highscore::getScoreName(int room) {
return &tabel[room].name[0];
}
diff --git a/source/code/highscore.h b/source/code/highscore.h
index 10cffdf..97b6bc8 100644
--- a/source/code/highscore.h
+++ b/source/code/highscore.h
@@ -54,5 +54,5 @@ public:
bool isHighScore(int);
void addScore(const std::string& newName, int);
int getScoreNumber(int);
- char* getScoreName(int);
+ const char* getScoreName(int);
};
diff --git a/source/code/main.cpp b/source/code/main.cpp
index 9180a2f..8d74004 100644
--- a/source/code/main.cpp
+++ b/source/code/main.cpp
@@ -1003,10 +1003,10 @@ void DrawHighscores(int x, int y, bool endless) {
snprintf(playerScore, sizeof(playerScore), "%i", theTopScoresTimeTrial.getScoreNumber(i));
}
if (endless) {
- strcpy(playerName,theTopScoresEndless.getScoreName(i));
+ snprintf(playerName, sizeof(playerName), "%s", theTopScoresEndless.getScoreName(i));
}
else {
- strcpy(playerName,theTopScoresTimeTrial.getScoreName(i));
+ snprintf(playerName, sizeof(playerName), "%s", theTopScoresTimeTrial.getScoreName(i));
}
nf_standard_blue_font.draw(screen, x+420,y+150+i*35, "%s",playerScore);
nf_standard_blue_font.draw(screen, x+60,y+150+i*35, "%s",playerName);
@@ -1675,7 +1675,7 @@ int PuzzleLevelSelect(int Type) {
//This function will promt for the user to select another file for puzzle mode
void changePuzzleLevels() {
char theFileName[30];
- strcpy(theFileName, PuzzleGetName().c_str());
+ snprintf(theFileName, sizeof(theFileName), "%s", PuzzleGetName().c_str());
for (int i=PuzzleGetName().length(); i<30; i++) {
theFileName[i]=' ';
}