summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralex <alex@ASUS>2018-09-19 15:18:25 +0200
committeralex <alex@ASUS>2018-09-19 15:18:25 +0200
commit005d688157f95163f452c5c395ac8aa4fa0610a7 (patch)
tree9ad17d3debcb13bc297335d679983159c9980893
parentdb072808ecf073168422ca908dc329d4122c29e1 (diff)
Use snprintf instead of strcpy & strcat
-rw-r--r--libalx/inc/alx_ncur.h3
-rw-r--r--libalx/src/alx_ncur.c16
-rw-r--r--modules/about/src/about.c27
-rw-r--r--modules/menu/inc/menu_iface.h1
-rw-r--r--modules/menu/src/parser.c6
-rw-r--r--modules/player/inc/player_clui.h4
-rw-r--r--modules/player/inc/player_gui.h4
-rw-r--r--modules/player/inc/player_iface.h4
-rw-r--r--modules/player/inc/player_tui.h4
-rw-r--r--modules/player/src/player_clui.c8
-rw-r--r--modules/player/src/player_gui.c16
-rw-r--r--modules/player/src/player_iface.c16
-rw-r--r--modules/player/src/player_tui.c6
-rw-r--r--modules/save/src/save.c46
-rw-r--r--modules/save/src/score.c79
15 files changed, 98 insertions, 142 deletions
diff --git a/libalx/inc/alx_ncur.h b/libalx/inc/alx_ncur.h
index bf5ed43..f1a774f 100644
--- a/libalx/inc/alx_ncur.h
+++ b/libalx/inc/alx_ncur.h
@@ -65,7 +65,8 @@
const char *format,
...);
- void alx_w_getstr (char *str,
+ void alx_w_getstr (char *dest,
+ int destsize,
int w,
int r,
const char *title,
diff --git a/libalx/src/alx_ncur.c b/libalx/src/alx_ncur.c
index 116a3bb..78de144 100644
--- a/libalx/src/alx_ncur.c
+++ b/libalx/src/alx_ncur.c
@@ -14,6 +14,7 @@
#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
+ /* strlen() */
#include <string.h>
/* wchar_t */
#include <wchar.h>
@@ -54,7 +55,7 @@ static double loop_w_getdbl (WINDOW *win,
double m, double def, double M);
static int64_t loop_w_getint (WINDOW *win,
double m, int64_t def, double M);
-static void loop_w_getstr (char *str, WINDOW *win);
+static void loop_w_getstr (char *dest, int destsize, WINDOW *win);
static void loop_w_getfname (const char *fpath, char *fname, bool exist,
WINDOW *win);
@@ -289,7 +290,7 @@ int64_t alx_w_getint (int w, int r, const char *title,
return Z;
}
-void alx_w_getstr (char *str,
+void alx_w_getstr (char *dest, int destsize,
int w, int r, const char *title,
const char *format, ...)
{
@@ -346,7 +347,7 @@ void alx_w_getstr (char *str,
win3 = newwin(h3, w3, r3, c3);
wbkgd(win3, A_REVERSE);
wrefresh(win3);
- loop_w_getstr(str, win3);
+ loop_w_getstr(dest, destsize, win3);
/* Delete window */
alx_win_del(win3);
@@ -612,7 +613,7 @@ static int64_t loop_w_getint (WINDOW *win,
return Z;
}
-static void loop_w_getstr (char *str, WINDOW *win)
+static void loop_w_getstr (char *dest, int destsize, WINDOW *win)
{
int i;
char buff [BUFF_SIZE];
@@ -637,7 +638,7 @@ static void loop_w_getstr (char *str, WINDOW *win)
}
if (!err) {
- strcpy(str, buff);
+ snprintf(dest, destsize, buff);
}
}
@@ -665,8 +666,7 @@ static void loop_w_getfname (const char *fpath, char *fname, bool exist,
} else if (sscanf(buff, " %s ", buff2) != 1) {
err = ERR_SSCANF;
} else {
- strcpy(file_path, fpath);
- strcat(file_path, buff2);
+ snprintf(file_path, FILENAME_MAX, "%s%s", fpath, buff2);
fp = fopen(file_path, "r");
@@ -691,7 +691,7 @@ static void loop_w_getfname (const char *fpath, char *fname, bool exist,
}
if (!err) {
- strcpy(fname, buff2);
+ snprintf(fname, FILENAME_MAX, buff2);
}
}
diff --git a/modules/about/src/about.c b/modules/about/src/about.c
index 6df46fc..3a2befe 100644
--- a/modules/about/src/about.c
+++ b/modules/about/src/about.c
@@ -11,8 +11,6 @@
* * * * * * * * * */
/* printf() */
#include <stdio.h>
- /* strcpy() & strcat() */
- #include <string.h>
/* * * * * * * * * *
* * * Other * * * * * * *
@@ -48,10 +46,7 @@ char share_path [FILENAME_MAX];
******************************************************************************/
void about_init (void)
{
- strcpy(share_path, INSTALL_SHARE_DIR);
- strcat(share_path, "/");
- strcat(share_path, SHARE_DIR);
- strcat(share_path, "/");
+ snprintf(share_path, FILENAME_MAX, "%s/%s/", INSTALL_SHARE_DIR, SHARE_DIR);
}
void print_cpright (void)
@@ -59,9 +54,7 @@ void print_cpright (void)
char file_name [FILENAME_MAX];
char str [BUFF_SIZE_TEXT];
- strcpy(file_name, share_path);
- strcat(file_name, "/");
- strcat(file_name, "COPYRIGHT.txt");
+ snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "COPYRIGHT.txt");
alx_snprint_file(str, BUFF_SIZE_TEXT, file_name);
@@ -75,9 +68,7 @@ void print_disclaim (void)
char file_name [FILENAME_MAX];
char str [BUFF_SIZE_TEXT];
- strcpy(file_name, share_path);
- strcat(file_name, "/");
- strcat(file_name, "DISCLAIMER.txt");
+ snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "DISCLAIMER.txt");
alx_snprint_file(str, BUFF_SIZE_TEXT, file_name);
@@ -91,9 +82,7 @@ void print_help (void)
char file_name [FILENAME_MAX];
char str [BUFF_SIZE_TEXT];
- strcpy(file_name, share_path);
- strcat(file_name, "/");
- strcat(file_name, "HELP.txt");
+ snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "HELP.txt");
alx_snprint_file(str, BUFF_SIZE_TEXT, file_name);
@@ -107,9 +96,7 @@ void print_license (void)
char file_name [FILENAME_MAX];
char str [BUFF_SIZE_TEXT];
- strcpy(file_name, share_path);
- strcat(file_name, "/");
- strcat(file_name, "LICENSE.txt");
+ snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "LICENSE.txt");
alx_snprint_file(str, BUFF_SIZE_TEXT, file_name);
@@ -123,9 +110,7 @@ void print_usage (void)
char file_name [FILENAME_MAX];
char str [BUFF_SIZE_TEXT];
- strcpy(file_name, share_path);
- strcat(file_name, "/");
- strcat(file_name, "USAGE.txt");
+ snprintf(file_name, FILENAME_MAX, "%s/%s", share_path, "USAGE.txt");
alx_snprint_file(str, BUFF_SIZE_TEXT, file_name);
diff --git a/modules/menu/inc/menu_iface.h b/modules/menu/inc/menu_iface.h
index 89e4326..481e6cb 100644
--- a/modules/menu/inc/menu_iface.h
+++ b/modules/menu/inc/menu_iface.h
@@ -51,6 +51,7 @@ extern struct Menu_Iface_Variables menu_iface_variables;
******************************************************************************/
void menu_iface_init (void);
void menu_iface_init_iface (void);
+void menu_iface_cleanup (void);
void menu_iface_board (int *level, int *rows, int *cols, int *mines);
void menu_iface (void);
diff --git a/modules/menu/src/parser.c b/modules/menu/src/parser.c
index fc2aaf1..4333bb7 100644
--- a/modules/menu/src/parser.c
+++ b/modules/menu/src/parser.c
@@ -10,10 +10,10 @@
* * * Standard * * * * * *
* * * * * * * * * */
#include <getopt.h>
+ /* FILE & fopen() & snprintf() & FILENAME_MAX */
#include <stdio.h>
/* exit() */
#include <stdlib.h>
- #include <string.h>
/* * * * * * * * * *
* * * Other * * * * * * *
@@ -176,8 +176,8 @@ static void parse_file (char* argument)
} else {
fclose(fp);
- strcpy(saved_path, "");
- strcpy(saved_name, argument);
+ sprintf(saved_path, "");
+ snprintf(saved_name, FILENAME_MAX, argument);
}
}
diff --git a/modules/player/inc/player_clui.h b/modules/player/inc/player_clui.h
index 6492054..2d92a38 100644
--- a/modules/player/inc/player_clui.h
+++ b/modules/player/inc/player_clui.h
@@ -58,8 +58,8 @@ void player_clui (const struct Game_Iface_Out *board,
const char *subtitle,
int *action);
-void player_clui_save_name (const char *filepath, char *filename);
-void player_clui_score_name (char *player_name);
+void player_clui_save_name (const char *filepath, char *filename, int destsize);
+void player_clui_score_name (char *player_name, int destsize);
/******************************************************************************
diff --git a/modules/player/inc/player_gui.h b/modules/player/inc/player_gui.h
index d98bda6..cca8677 100644
--- a/modules/player/inc/player_gui.h
+++ b/modules/player/inc/player_gui.h
@@ -64,8 +64,8 @@ int player_gui (const struct Game_Iface_Out *board,
const char *title,
const char *subtitle);
-void player_gui_save_name (const char *filepath, char *filename);
-void player_gui_score_name (char *player_name);
+void player_gui_save_name (const char *filepath, char *filename, int destsize);
+void player_gui_score_name (char *player_name, int destsize);
void player_gui_cleanup (void);
diff --git a/modules/player/inc/player_iface.h b/modules/player/inc/player_iface.h
index 2430002..a60a0ac 100644
--- a/modules/player/inc/player_iface.h
+++ b/modules/player/inc/player_iface.h
@@ -77,8 +77,8 @@ int player_iface_start (int *pos_row, int *pos_col);
void player_iface (const struct Game_Iface_Out *game_iface_out,
const struct Game_Iface_Score *game_iface_score,
struct Game_Iface_In *game_iface_in);
-void player_iface_save_name (const char *filepath, char *filename);
-void player_iface_score_name (char *player_name);
+void player_iface_save_name (const char *filepath, char *filename, int destsize);
+void player_iface_score_name (char *player_name, int destsize);
void player_iface_cleanup (void);
diff --git a/modules/player/inc/player_tui.h b/modules/player/inc/player_tui.h
index 4070147..6c0e7e2 100644
--- a/modules/player/inc/player_tui.h
+++ b/modules/player/inc/player_tui.h
@@ -103,8 +103,8 @@ int player_tui (const struct Game_Iface_Out *board,
const char *subtitle,
int *action);
-void player_tui_save_name (const char *filepath, char *filename);
-void player_tui_score_name (char *player_name);
+void player_tui_save_name (const char *filepath, char *filename, int destsize);
+void player_tui_score_name (char *player_name, int destsize);
void player_tui_cleanup (void);
diff --git a/modules/player/src/player_clui.c b/modules/player/src/player_clui.c
index 6d6ade6..f1d890c 100644
--- a/modules/player/src/player_clui.c
+++ b/modules/player/src/player_clui.c
@@ -104,16 +104,16 @@ void player_clui (const struct Game_Iface_Out *board,
oldaction = *action;
}
-void player_clui_save_name (const char *filepath, char *filename)
+void player_clui_save_name (const char *filepath, char *filename, int destsize)
{
puts("File name:");
- scanf(" %100c ", filename);
+ fgets(filename, destsize, stdin);
}
-void player_clui_score_name (char *player_name)
+void player_clui_score_name (char *player_name, int destsize)
{
puts("Your name:");
- scanf(" %100c ", player_name);
+ fgets(player_name, destsize, stdin);
}
diff --git a/modules/player/src/player_gui.c b/modules/player/src/player_gui.c
index b93eafb..116d6ab 100644
--- a/modules/player/src/player_gui.c
+++ b/modules/player/src/player_gui.c
@@ -12,8 +12,8 @@
#include <gtk/gtk.h>
/* true & false */
#include <stdbool.h>
- /* strcpy() */
- #include <string.h>
+ /* snprintf() */
+ #include <stdio.h>
/* * * * * * * * * *
* * * Other * * * * * * *
@@ -238,7 +238,7 @@ int player_gui (const struct Game_Iface_Out *board,
return 0;
}
-void player_gui_save_name (const char *filepath, char *filename)
+void player_gui_save_name (const char *filepath, char *filename, int destsize)
{
#if 0
/* Input box */
@@ -252,7 +252,7 @@ void player_gui_save_name (const char *filepath, char *filename)
#endif
}
-void player_gui_score_name (char *player_name)
+void player_gui_score_name (char *player_name, int destsize)
{
#if 0
/* Input box */
@@ -332,14 +332,14 @@ static void show_board_start(struct Player_Iface_Position *position,
const char *subtitle)
{
/* Title */
- strcpy(label[0].text, title);
+ snprintf(label[0].text, LINE_SIZE, title);
gtk_label_set_text(GTK_LABEL(label[0].ptr), label[0].text);
/* Board */
board_loop_start(position);
/* Subtitle */
- strcpy(label[1].text, subtitle);
+ snprintf(label[1].text, LINE_SIZE, subtitle);
gtk_label_set_text(GTK_LABEL(label[1].ptr), label[1].text);
/* Refresh */
@@ -371,14 +371,14 @@ static void show_board (const struct Game_Iface_Out *board,
const char *subtitle)
{
/* Title */
- strcpy(label[0].text, title);
+ snprintf(label[0].text, LINE_SIZE, title);
gtk_label_set_text(GTK_LABEL(label[0].ptr), label[0].text);
/* Board */
board_loop(board, position);
/* Subtitle */
- strcpy(label[1].text, subtitle);
+ snprintf(label[1].text, LINE_SIZE, subtitle);
gtk_label_set_text(GTK_LABEL(label[1].ptr), label[1].text);
/* Refresh */
diff --git a/modules/player/src/player_iface.c b/modules/player/src/player_iface.c
index ea32b4f..357594c 100644
--- a/modules/player/src/player_iface.c
+++ b/modules/player/src/player_iface.c
@@ -209,36 +209,36 @@ void player_iface (const struct Game_Iface_Out *game_iface_out,
player_iface_act(game_iface_in, player_action);
}
-void player_iface_save_name (const char *filepath, char *filename)
+void player_iface_save_name (const char *filepath, char *filename, int destsize)
{
switch (player_iface_mode) {
case PLAYER_IFACE_CLUI:
- player_clui_save_name(filepath, filename);
+ player_clui_save_name(filepath, filename, destsize);
break;
case PLAYER_IFACE_TUI:
- player_tui_save_name(filepath, filename);
+ player_tui_save_name(filepath, filename, destsize);
break;
case PLAYER_IFACE_GUI:
- player_gui_save_name(filepath, filename);
+ player_gui_save_name(filepath, filename, destsize);
break;
}
}
-void player_iface_score_name (char *player_name)
+void player_iface_score_name (char *player_name, int destsize)
{
switch (player_iface_mode) {
case PLAYER_IFACE_CLUI:
- player_clui_score_name(player_name);
+ player_clui_score_name(player_name, destsize);
break;
case PLAYER_IFACE_TUI:
- player_tui_score_name(player_name);
+ player_tui_score_name(player_name, destsize);
break;
case PLAYER_IFACE_GUI:
- player_gui_score_name(player_name);
+ player_gui_score_name(player_name, destsize);
break;
}
}
diff --git a/modules/player/src/player_tui.c b/modules/player/src/player_tui.c
index f6ea181..aaaeb3a 100644
--- a/modules/player/src/player_tui.c
+++ b/modules/player/src/player_tui.c
@@ -169,7 +169,7 @@ int player_tui (const struct Game_Iface_Out *board,
*action = usr_input();
}
-void player_tui_save_name (const char *filepath, char *filename)
+void player_tui_save_name (const char *filepath, char *filename, int destsize)
{
/* Input box */
int w;
@@ -181,7 +181,7 @@ void player_tui_save_name (const char *filepath, char *filename)
alx_w_getfname(filepath, filename, false, w, r, "File name:", NULL);
}
-void player_tui_score_name (char *player_name)
+void player_tui_score_name (char *player_name, int destsize)
{
/* Input box */
int w;
@@ -190,7 +190,7 @@ void player_tui_score_name (char *player_name)
r = 10;
/* Request name */
- alx_w_getstr(player_name, w, r, "Your name:", NULL);
+ alx_w_getstr(player_name, destsize, w, r, "Your name:", NULL);
}
void player_tui_cleanup (void)
diff --git a/modules/save/src/save.c b/modules/save/src/save.c
index af18609..b4651b2 100644
--- a/modules/save/src/save.c
+++ b/modules/save/src/save.c
@@ -13,12 +13,10 @@
#include <errno.h>
/* bool */
#include <stdbool.h>
- /* fscanf() & fprintf() & FILE & FILENAME_MAX */
+ /* fscanf() & fprintf() & FILE & FILENAME_MAX & snprintf() */
#include <stdio.h>
/* getenv() */
#include <stdlib.h>
- /* strcpy() & strcat() */
- #include <string.h>
/* mkdir */
#if defined OS_LINUX
#include <sys/stat.h>
@@ -51,19 +49,10 @@ char saved_name [FILENAME_MAX];
******************************************************************************/
void save_init (void)
{
- strcpy(home_path, getenv(ENV_HOME));
-
- strcpy(user_game_path, home_path);
- strcat(user_game_path, "/");
- strcat(user_game_path, USER_GAME_DIR);
- strcat(user_game_path, "/");
-
- strcpy(saved_path, home_path);
- strcat(saved_path, "/");
- strcat(saved_path, USER_SAVED_DIR);
- strcat(saved_path, "/");
-
- strcpy(saved_name, "");
+ snprintf(home_path, FILENAME_MAX, "%s/", getenv(ENV_HOME));
+ snprintf(user_game_path, FILENAME_MAX, "%s/%s/", home_path, USER_GAME_DIR);
+ snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR);
+ sprintf(saved_name, "");
int err;
#if defined OS_LINUX
@@ -99,10 +88,7 @@ void save_init (void)
void save_clr (void)
{
- strcpy(saved_path, home_path);
- strcat(saved_path, "/");
- strcat(saved_path, USER_SAVED_DIR);
- strcat(saved_path, "/");
+ snprintf(saved_path, FILENAME_MAX, "%s/%s/", home_path, USER_SAVED_DIR);
}
void load_game_file (void)
@@ -113,8 +99,7 @@ void load_game_file (void)
int i;
int j;
- strcpy(file_name, saved_path);
- strcat(file_name, saved_name);
+ snprintf(file_name, FILENAME_MAX, "%s/%s/", saved_path, saved_name);
fp = fopen(file_name, "r");
if (fp) {
@@ -160,23 +145,22 @@ void save_game_file (char *filepath)
/* Default path & name */
save_clr();
- strcpy(saved_name, SAVED_NAME_DEFAULT);
+ snprintf(saved_name, FILENAME_MAX, "%s", SAVED_NAME_DEFAULT);
/* Request file name */
- player_iface_save_name(filepath, saved_name);
+ player_iface_save_name(filepath, saved_name, FILENAME_MAX);
/* Look for an unused name of the type 'name_XXX.mine'. */
bool x;
x = true;
for (i = 0; x; i++) {
if (filepath == NULL) {
- strcpy(file_name, saved_path);
+ snprintf(file_name, FILENAME_MAX, "%s/%s%s%s",
+ saved_path, saved_name, file_num, FILE_EXTENSION);
} else {
- strcpy(file_name, filepath);
+ snprintf(file_name, FILENAME_MAX, "%s/%s%s%s",
+ filepath, saved_name, file_num, FILE_EXTENSION);
}
- strcat(file_name, saved_name);
- strcat(file_name, file_num);
- strcat(file_name, FILE_EXTENSION);
fp = fopen(file_name, "r");
if (fp) {
@@ -188,8 +172,8 @@ void save_game_file (char *filepath)
file_num[4] = '\0';
} else {
x = false;
- strcat(saved_name, file_num);
- strcat(saved_name, FILE_EXTENSION);
+ snprintf(saved_name, FILENAME_MAX, "%s%s%s",
+ saved_name, file_num, FILE_EXTENSION);
}
}
diff --git a/modules/save/src/score.c b/modules/save/src/score.c
index 337cdcf..31ee474 100644
--- a/modules/save/src/score.c
+++ b/modules/save/src/score.c
@@ -9,12 +9,10 @@
/* * * * * * * * * *
* * * Standard * * * * * *
* * * * * * * * * */
- /* fscanf() & fprintf() & FILE & FILENAME_MAX */
+ /* fscanf() & fprintf() & FILE & FILENAME_MAX & snprintf() */
#include <stdio.h>
/* exit() */
#include <stdlib.h>
- /* strcpy() & strcat() */
- #include <string.h>
/* time_t & time() & struct tm & localtime() */
#include <time.h>
@@ -65,57 +63,44 @@ static void read_scores_file (char *file_name);
******************************************************************************/
void score_init (void)
{
- strcpy(var_path, INSTALL_VAR_DIR);
- strcat(var_path, "/");
- strcat(var_path, VAR_DIR);
- strcat(var_path, "/");
-
- strcpy(var_hiscores_path, var_path);
- strcat(var_hiscores_path, "/");
- strcat(var_hiscores_path, HISCORES_DIR);
- strcat(var_hiscores_path, "/");
-
- strcpy(var_boards_beginner_path, var_path);
- strcat(var_boards_beginner_path, "/");
- strcat(var_boards_beginner_path, BOARDS_BEGINNER_DIR);
- strcat(var_boards_beginner_path, "/");
-
- strcpy(var_boards_intermediate_path, var_path);
- strcat(var_boards_intermediate_path, "/");
- strcat(var_boards_intermediate_path, BOARDS_INTERMEDIATE_DIR);
- strcat(var_boards_intermediate_path, "/");
-
- strcpy(var_boards_expert_path, var_path);
- strcat(var_boards_expert_path, "/");
- strcat(var_boards_expert_path, BOARDS_EXPERT_DIR);
- strcat(var_boards_expert_path, "/");
-
- strcpy(var_boards_custom_path, var_path);
- strcat(var_boards_custom_path, "/");
- strcat(var_boards_custom_path, BOARDS_CUSTOM_DIR);
- strcat(var_boards_custom_path, "/");
-
- strcpy(var_hiscores_beginner_name, HISCORES_BEGINNER_NAME);
- strcpy(var_hiscores_intermediate_name, HISCORES_INTERMEDIATE_NAME);
- strcpy(var_hiscores_expert_name, HISCORES_EXPERT_NAME);
+ snprintf(var_path, FILENAME_MAX, "%s/%s/",
+ INSTALL_VAR_DIR, VAR_DIR);
+ snprintf(var_hiscores_path, FILENAME_MAX, "%s/%s/",
+ var_path, HISCORES_DIR);
+ snprintf(var_boards_beginner_path, FILENAME_MAX, "%s/%s/",
+ var_path, BOARDS_BEGINNER_DIR);
+ snprintf(var_boards_intermediate_path, FILENAME_MAX, "%s/%s/",
+ var_path, BOARDS_INTERMEDIATE_DIR);
+ snprintf(var_boards_expert_path, FILENAME_MAX, "%s/%s/",
+ var_path, BOARDS_EXPERT_DIR);
+ snprintf(var_boards_custom_path, FILENAME_MAX, "%s/%s/",
+ var_path, BOARDS_CUSTOM_DIR);
+ snprintf(var_hiscores_beginner_name, FILENAME_MAX, "%s",
+ HISCORES_BEGINNER_NAME);
+ snprintf(var_hiscores_intermediate_name, FILENAME_MAX, "%s",
+ HISCORES_INTERMEDIATE_NAME);
+ snprintf(var_hiscores_expert_name, FILENAME_MAX, "%s",
+ HISCORES_EXPERT_NAME);
}
void save_score (const struct Game_Iface_Score *game_iface_score)
{
/* File name */
char file_name [FILENAME_MAX];
- strcpy(file_name, var_hiscores_path);
switch (game_iface_score->level) {
case GAME_IFACE_LEVEL_BEGINNER:
- strcat(file_name, var_hiscores_beginner_name);
+ snprintf(file_name, FILENAME_MAX, "%s/%s",
+ var_hiscores_path, var_hiscores_beginner_name);
break;
case GAME_IFACE_LEVEL_INTERMEDIATE:
- strcat(file_name, var_hiscores_intermediate_name);
+ snprintf(file_name, FILENAME_MAX, "%s/%s",
+ var_hiscores_path, var_hiscores_intermediate_name);
break;
case GAME_IFACE_LEVEL_EXPERT:
- strcat(file_name, var_hiscores_expert_name);
+ snprintf(file_name, FILENAME_MAX, "%s/%s",
+ var_hiscores_path, var_hiscores_expert_name);
break;
}
@@ -127,7 +112,7 @@ void save_score (const struct Game_Iface_Score *game_iface_score)
/* Player name (foo is default) */
char player_name [BUFF_SIZE];
- player_iface_score_name(player_name);
+ player_iface_score_name(player_name, BUFF_SIZE);
/* Write to file (append) */
FILE *fp;
@@ -163,18 +148,18 @@ void read_scores (void)
char file_name [FILENAME_MAX];
/* Beginner */
- strcpy(file_name, var_hiscores_path);
- strcat(file_name, var_hiscores_beginner_name);
+ snprintf(file_name, FILENAME_MAX, "%s/%s",
+ var_hiscores_path, var_hiscores_beginner_name);
read_scores_file(file_name);
/* Intermediate */
- strcpy(file_name, var_hiscores_path);
- strcat(file_name, var_hiscores_intermediate_name);
+ snprintf(file_name, FILENAME_MAX, "%s/%s",
+ var_hiscores_path, var_hiscores_intermediate_name);
read_scores_file(file_name);
/* Expert */
- strcpy(file_name, var_hiscores_path);
- strcat(file_name, var_hiscores_expert_name);
+ snprintf(file_name, FILENAME_MAX, "%s/%s",
+ var_hiscores_path, var_hiscores_expert_name);
read_scores_file(file_name);
}