aboutsummaryrefslogtreecommitdiffstats
path: root/FICS/obsproc.c
diff options
context:
space:
mode:
Diffstat (limited to 'FICS/obsproc.c')
-rw-r--r--FICS/obsproc.c87
1 files changed, 56 insertions, 31 deletions
diff --git a/FICS/obsproc.c b/FICS/obsproc.c
index 43954ff..2353c60 100644
--- a/FICS/obsproc.c
+++ b/FICS/obsproc.c
@@ -32,6 +32,7 @@
Markus Uhlin 25/01/18 Fixed -Wshadow
Markus Uhlin 25/03/15 Fixed possible buffer overflow
in FindHistory2().
+ Markus Uhlin 25/04/06 Fixed Clang Tidy warnings.
*/
#include "stdinclude.h"
@@ -152,6 +153,9 @@ com_games(int p, param_list param)
wp = garray[i].white;
bp = garray[i].black;
+ UNUSED_VAR(wp);
+ UNUSED_VAR(bp);
+
if ((!selected) &&
s &&
strncasecmp(s, garray[i].white_name, slen) &&
@@ -380,9 +384,8 @@ com_allobservers(int p, param_list param)
start = 0;
end = g_num;
} else if ((obgame >= g_num) ||
- ((obgame < g_num) &&
- ((garray[obgame].status != GAME_ACTIVE) &&
- (garray[obgame].status != GAME_EXAMINE)))) {
+ (garray[obgame].status != GAME_ACTIVE &&
+ garray[obgame].status != GAME_EXAMINE)) {
pprintf(p, "There is no such game.\n");
return COM_OK;
} else {
@@ -980,11 +983,16 @@ FindHistory(int p, int p1, int p_game)
ret = fscanf(fpHist, "%d %*c %*d %*c %*d %*s %*s %*d %*d %*d "
"%*d %*s %*s %ld", &index, &when);
- if (ret != 2)
- warn("%s: %s: corrupt", __func__, &fileName[0]);
- } while (!feof(fpHist) && index != p_game);
+ if (ret != 2) {
+ warnx("%s: %s: corrupt", __func__, fileName);
+ fclose(fpHist);
+ return NULL;
+ }
+ } while (!feof(fpHist) &&
+ !ferror(fpHist) &&
+ index != p_game);
- if (feof(fpHist)) {
+ if (feof(fpHist) || ferror(fpHist)) {
pprintf(p, "There is no history game %d for %s.\n", p_game,
parray[p1].name);
fclose(fpHist);
@@ -1019,11 +1027,16 @@ FindHistory2(int p, int p1, int p_game, char *End, const size_t End_size)
"%%*d %%*d %%*d %%*s %%%zus %%ld\n", (End_size - 1));
do {
- if (fscanf(fpHist, fmt, &index, End, &when) != 3)
- warn("%s: %s: corrupt", __func__, &fileName[0]);
- } while (!feof(fpHist) && index != p_game);
+ if (fscanf(fpHist, fmt, &index, End, &when) != 3) {
+ warnx("%s: %s: corrupt", __func__, fileName);
+ fclose(fpHist);
+ return NULL;
+ }
+ } while (!feof(fpHist) &&
+ !ferror(fpHist) &&
+ index != p_game);
- if (feof(fpHist)) {
+ if (feof(fpHist) || ferror(fpHist)) {
pprintf(p, "There is no history game %d for %s.\n", p_game,
parray[p1].name);
fclose(fpHist);
@@ -1757,21 +1770,13 @@ com_journal(int p, param_list param)
PRIVATE void
jsave_journalentry(int p, char save_spot, int p1, char from_spot, char *to_file)
{
- FILE *Game;
- char *name_from = parray[p1].login;
- char *name_to = parray[p].login;
- char BlackName[MAX_LOGIN_NAME + 1];
- char WhiteName[MAX_LOGIN_NAME + 1];
- char command[MAX_FILENAME_SIZE * 2 + 3];
- char eco[100];
- char ending[100];
- char fname[MAX_FILENAME_SIZE];
- char fname2[MAX_FILENAME_SIZE];
- char result[100];
- char type[100];
- int BlackRating;
- int WhiteRating;
- int i, t;
+ FILE *Game;
+ char *name_from = parray[p1].login;
+ char *name_to = parray[p].login;
+ char command[MAX_FILENAME_SIZE * 2 + 3];
+ char fname[MAX_FILENAME_SIZE];
+ char fname2[MAX_FILENAME_SIZE];
+ struct JGI_context ctx;
msnprintf(fname, sizeof fname, "%s/%c/%s.%c", journal_dir, name_from[0],
name_from, from_spot);
@@ -1801,14 +1806,34 @@ jsave_journalentry(int p, char save_spot, int p1, char from_spot, char *to_file)
msnprintf(fname, sizeof fname, "%s/player_data/%c/%s.%s", stats_dir,
name_to[0], name_to, STATS_JOURNAL);
- if (!journal_get_info(p, from_spot, WhiteName, &WhiteRating,
- BlackName, &BlackRating, type, &t, &i, eco, ending, result, fname))
+ /*
+ * Init context
+ */
+ ctx.p = p;
+ ctx.from_spot = from_spot;
+ ctx.WhiteRating = 0;
+ ctx.BlackRating = 0;
+ ctx.t = 0;
+ ctx.i = 0;
+ memset(ctx.WhiteName, 0, sizeof(ctx.WhiteName));
+ memset(ctx.BlackName, 0, sizeof(ctx.BlackName));
+ memset(ctx.type, 0, sizeof(ctx.type));
+ memset(ctx.eco, 0, sizeof(ctx.eco));
+ memset(ctx.ending, 0, sizeof(ctx.ending));
+ memset(ctx.result, 0, sizeof(ctx.result));
+
+ if (!journal_get_info(&ctx, fname))
return;
addjournalitem(p, toupper(save_spot),
- WhiteName, WhiteRating,
- BlackName, BlackRating,
- type, t, i, eco, ending, result, to_file);
+ ctx.WhiteName, ctx.WhiteRating,
+ ctx.BlackName, ctx.BlackRating,
+ ctx.type,
+ ctx.t, ctx.i,
+ ctx.eco,
+ ctx.ending,
+ ctx.result,
+ to_file);
pprintf(p, "Journal entry %s %c saved in slot %c in journal.\n",
parray[p1].name, toupper(from_spot), toupper(save_spot));
}