From 8bcfa8db8a604ed9d0cde07bb20bf8089362c3e9 Mon Sep 17 00:00:00 2001 From: Markus Uhlin Date: Sun, 31 Dec 2023 22:33:46 +0100 Subject: Trim the newline using strcspn() --- FICS/playerdb.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'FICS/playerdb.c') diff --git a/FICS/playerdb.c b/FICS/playerdb.c index 904ceb5..065d1d2 100644 --- a/FICS/playerdb.c +++ b/FICS/playerdb.c @@ -356,9 +356,9 @@ ReadV1PlayerFmt(int p, player *pp, FILE *fp, char *file, int version) /* * Name */ - fgets(tmp2, sizeof tmp2, fp); + (void)fgets(tmp2, sizeof tmp2, fp); if (strcmp(tmp2, "NONE\n")) { - tmp2[strlen(tmp2) - 1] = '\0'; + tmp2[strcspn(tmp2, "\n")] = '\0'; pp->name = xstrdup(tmp2); } else { pp->name = NULL; @@ -367,9 +367,9 @@ ReadV1PlayerFmt(int p, player *pp, FILE *fp, char *file, int version) /* * Full name */ - fgets(tmp2, sizeof tmp2, fp); + (void)fgets(tmp2, sizeof tmp2, fp); if (strcmp(tmp2, "NONE\n")) { - tmp2[strlen(tmp2) - 1] = '\0'; + tmp2[strcspn(tmp2, "\n")] = '\0'; pp->fullName = xstrdup(tmp2); } else { pp->fullName = NULL; @@ -378,9 +378,9 @@ ReadV1PlayerFmt(int p, player *pp, FILE *fp, char *file, int version) /* * Password */ - fgets(tmp2, sizeof tmp2, fp); + (void)fgets(tmp2, sizeof tmp2, fp); if (strcmp(tmp2, "NONE\n")) { - tmp2[strlen(tmp2) - 1] = '\0'; + tmp2[strcspn(tmp2, "\n")] = '\0'; pp->passwd = xstrdup(tmp2); } else { pp->passwd = NULL; @@ -389,9 +389,9 @@ ReadV1PlayerFmt(int p, player *pp, FILE *fp, char *file, int version) /* * Email */ - fgets(tmp2, sizeof tmp2, fp); + (void)fgets(tmp2, sizeof tmp2, fp); if (strcmp(tmp2, "NONE\n")) { - tmp2[strlen(tmp2) - 1] = '\0'; + tmp2[strcspn(tmp2, "\n")] = '\0'; pp->emailAddress = xstrdup(tmp2); } else { pp->emailAddress = NULL; -- cgit v1.2.3