aboutsummaryrefslogtreecommitdiffstats
path: root/FICS
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2026-03-03 23:23:14 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2026-03-03 23:23:14 +0100
commit100611ed58b019e1f2820f07c8224e029ea1b0a1 (patch)
treef57fd2d23e412d282c65e0a192932e3cd916fa59 /FICS
parentd46e5bdc7d626eab0154c84887d0e72b7211044a (diff)
Defined and made use of get_intval() and get_timeval() which uses strtonum()
Diffstat (limited to 'FICS')
-rw-r--r--FICS/gamedb.c51
-rw-r--r--FICS/gamedb.h2
2 files changed, 38 insertions, 15 deletions
diff --git a/FICS/gamedb.c b/FICS/gamedb.c
index 4de910e..0255856 100644
--- a/FICS/gamedb.c
+++ b/FICS/gamedb.c
@@ -62,6 +62,7 @@
#include "command.h"
#include "config.h"
#include "eco.h"
+#include "ficslim.h"
#include "ficsmain.h"
#include "gamedb.h"
#include "gameproc.h"
@@ -73,6 +74,7 @@
#include "utils.h"
#if __linux__
+#include <bsd/stdlib.h>
#include <bsd/string.h>
#endif
@@ -1043,16 +1045,35 @@ ReadGameState(FILE *fp, game_state_t *gs, int version)
}
PUBLIC int
+get_intval(const char *nptr)
+{
+ const char *errstr = NULL;
+ const int val = (int) strtonum(nptr, INT_MIN, INT_MAX, &errstr);
+
+ return (errstr ? 0 : val);
+}
+
+PUBLIC time_t
+get_timeval(const char *nptr)
+{
+ const char *errstr = NULL;
+ const time_t val = (time_t) strtonum(nptr, g_time_min, g_time_max,
+ &errstr);
+
+ return (errstr ? 0 : val);
+}
+
+PUBLIC int
got_attr_value(int g, char *attr, char *value, FILE *fp, char *file)
{
if (!strcmp(attr, "w_init:")) {
- garray[g].wInitTime = atoi(value);
+ garray[g].wInitTime = get_intval(value);
} else if (!strcmp(attr, "w_inc:")) {
- garray[g].wIncrement = atoi(value);
+ garray[g].wIncrement = get_intval(value);
} else if (!strcmp(attr, "b_init:")) {
- garray[g].bInitTime = atoi(value);
+ garray[g].bInitTime = get_intval(value);
} else if (!strcmp(attr, "b_inc:")) {
- garray[g].bIncrement = atoi(value);
+ garray[g].bIncrement = get_intval(value);
} else if (!strcmp(attr, "white_name:")) {
mstrlcpy(garray[g].white_name, value,
sizeof(garray[g].white_name));
@@ -1060,27 +1081,27 @@ got_attr_value(int g, char *attr, char *value, FILE *fp, char *file)
mstrlcpy(garray[g].black_name, value,
sizeof(garray[g].black_name));
} else if (!strcmp(attr, "white_rating:")) {
- garray[g].white_rating = atoi(value);
+ garray[g].white_rating = get_intval(value);
} else if (!strcmp(attr, "black_rating:")) {
- garray[g].black_rating = atoi(value);
+ garray[g].black_rating = get_intval(value);
} else if (!strcmp(attr, "result:")) {
- garray[g].result = atoi(value);
+ garray[g].result = get_intval(value);
} else if (!strcmp(attr, "timestart:")) {
- garray[g].timeOfStart = atoi(value);
+ garray[g].timeOfStart = get_timeval(value);
} else if (!strcmp(attr, "w_time:")) {
- garray[g].wTime = atoi(value);
+ garray[g].wTime = get_intval(value);
} else if (!strcmp(attr, "b_time:")) {
- garray[g].bTime = atoi(value);
+ garray[g].bTime = get_intval(value);
} else if (!strcmp(attr, "clockstopped:")) {
- garray[g].clockStopped = atoi(value);
+ garray[g].clockStopped = get_intval(value);
} else if (!strcmp(attr, "rated:")) {
- garray[g].rated = atoi(value);
+ garray[g].rated = get_intval(value);
} else if (!strcmp(attr, "private:")) {
- garray[g].private = atoi(value);
+ garray[g].private = get_intval(value);
} else if (!strcmp(attr, "type:")) {
- garray[g].type = atoi(value);
+ garray[g].type = get_intval(value);
} else if (!strcmp(attr, "halfmoves:")) {
- if ((garray[g].numHalfMoves = atoi(value)) == 0)
+ if ((garray[g].numHalfMoves = get_intval(value)) == 0)
return 0;
else if (garray[g].numHalfMoves < 0 ||
(size_t)garray[g].numHalfMoves > INT_MAX / sizeof(move_t)) {
diff --git a/FICS/gamedb.h b/FICS/gamedb.h
index 3b2e018..03aa9ee 100644
--- a/FICS/gamedb.h
+++ b/FICS/gamedb.h
@@ -205,6 +205,8 @@ extern void game_write_complete(int, int, char *);
extern void send_board_to(int, int);
extern void send_boards(int);
+extern int get_intval(const char *);
+extern time_t get_timeval(const char *);
__FICS_END_DECLS
#endif