From: Holger Schemel Date: Mon, 15 Mar 1999 00:38:13 +0000 (+0100) Subject: rnd-19990315-1-src X-Git-Tag: 1.4.0^2~31 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=5caf02865ba54b967aa085c4221040113a9e1976;p=rocksndiamonds.git rnd-19990315-1-src --- diff --git a/src/files.c b/src/files.c index a7238908..00099201 100644 --- a/src/files.c +++ b/src/files.c @@ -827,15 +827,15 @@ void LoadScore(int level_nr) fscanf(file, "%d", &highscore[i].Score); fgets(line, MAX_LINE_LEN, file); - if (line[strlen(line)-1] == '\n') - line[strlen(line)-1] = '\0'; + if (line[strlen(line) - 1] == '\n') + line[strlen(line) - 1] = '\0'; for (line_ptr = line; *line_ptr; line_ptr++) { if (*line_ptr != ' ' && *line_ptr != '\t' && *line_ptr != '\0') { - strncpy(highscore[i].Name, line_ptr, MAX_NAMELEN - 1); - highscore[i].Name[MAX_NAMELEN - 1] = '\0'; + strncpy(highscore[i].Name, line_ptr, MAX_PLAYER_NAME_LEN); + highscore[i].Name[MAX_PLAYER_NAME_LEN] = '\0'; break; } } @@ -1572,11 +1572,11 @@ void LoadSetup() freeSetupFileList(setup_file_list); /* needed to work around problems with fixed length strings */ - if (strlen(setup.player_name) >= MAX_NAMELEN) - setup.player_name[MAX_NAMELEN - 1] = '\0'; - else if (strlen(setup.player_name) < MAX_NAMELEN - 1) + if (strlen(setup.player_name) > MAX_PLAYER_NAME_LEN) + setup.player_name[MAX_PLAYER_NAME_LEN] = '\0'; + else if (strlen(setup.player_name) < MAX_PLAYER_NAME_LEN) { - char *new_name = checked_malloc(MAX_NAMELEN); + char *new_name = checked_malloc(MAX_PLAYER_NAME_LEN + 1); strcpy(new_name, setup.player_name); free(setup.player_name); diff --git a/src/game.c b/src/game.c index 48482c90..89ed530f 100644 --- a/src/game.c +++ b/src/game.c @@ -897,15 +897,16 @@ int NewHiScore() #ifdef ONE_PER_NAME put_into_list: #endif - strncpy(highscore[k].Name, setup.player_name, MAX_NAMELEN - 1); - highscore[k].Name[MAX_NAMELEN - 1] = '\0'; + strncpy(highscore[k].Name, setup.player_name, MAX_PLAYER_NAME_LEN); + highscore[k].Name[MAX_PLAYER_NAME_LEN] = '\0'; highscore[k].Score = local_player->score; position = k; break; } #ifdef ONE_PER_NAME - else if (!strncmp(setup.player_name, highscore[k].Name, MAX_NAMELEN - 1)) + else if (!strncmp(setup.player_name, highscore[k].Name, + MAX_PLAYER_NAME_LEN)) break; /* player already there with a higher score */ #endif diff --git a/src/main.h b/src/main.h index a625102c..fad880a4 100644 --- a/src/main.h +++ b/src/main.h @@ -201,7 +201,7 @@ typedef unsigned char byte; #define NUM_PIXMAPS 10 /* boundaries of arrays etc. */ -#define MAX_NAMELEN (10+1) +#define MAX_PLAYER_NAME_LEN 10 #define MAX_LEVEL_NAME_LEN 32 #define MAX_LEVEL_AUTHOR_LEN 32 #define MAX_TAPELEN (1000 * 50) /* max. time * framerate */ @@ -227,7 +227,7 @@ typedef unsigned char byte; struct HiScore { - char Name[MAX_NAMELEN]; + char Name[MAX_PLAYER_NAME_LEN + 1]; int Score; }; diff --git a/src/network.c b/src/network.c index 5d137f05..e16c0d9f 100644 --- a/src/network.c +++ b/src/network.c @@ -33,12 +33,10 @@ #include "screens.h" #include "misc.h" -#define MAX_PLAYER_NAME_LEN 14 - struct NetworkClientPlayerInfo { byte nr; - char name[MAX_PLAYER_NAME_LEN + 2]; + char name[MAX_PLAYER_NAME_LEN + 1]; struct NetworkClientPlayerInfo *next; }; diff --git a/src/screens.c b/src/screens.c index d494e99a..ed99fd40 100644 --- a/src/screens.c +++ b/src/screens.c @@ -763,7 +763,7 @@ void HandleTypeName(int newxpos, KeySym key) } if (((key >= XK_A && key <= XK_Z) || (key >= XK_a && key <= XK_z)) && - xpos < MAX_NAMELEN - 1) + xpos < MAX_PLAYER_NAME_LEN) { char ascii;