From ca165ccf4041e6341c656357eccdc3d99b26aee0 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Sun, 21 Jul 2024 18:40:25 +0200 Subject: [PATCH] lib/, src/: Remove useless casts in fgets(3) This patch can be replicated with the following semantic patch: $ cat fgets_cast.sp @@ expression a, b, c; @@ - fgets(a, (int) (b), c) + fgets(a, b, c) @@ expression a, b, c; @@ - fgets(a, (int) b, c) + fgets(a, b, c) @@ expression a, b, c; @@ - fgetsx(a, (int) (b), c) + fgetsx(a, b, c) @@ expression a, b, c; @@ - fgetsx(a, (int) b, c) + fgetsx(a, b, c) @@ expression a, b, c, p; @@ - p->fgets(a, (int) (b), c) + p->fgets(a, b, c) @@ expression a, b, c, p; @@ - p->fgets(a, (int) b, c) + p->fgets(a, b, c) which is applied as: $ find lib* src/ -type f \ | xargs spatch --sp-file ~/tmp/spatch/fgets_cast.sp --in-place; Signed-off-by: Alejandro Colomar --- lib/commonio.c | 4 +--- lib/gshadow.c | 4 +--- lib/setupenv.c | 2 +- src/chgpasswd.c | 2 +- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/commonio.c b/lib/commonio.c index 75f4d76ad..5a06a3e71 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -654,9 +654,7 @@ int commonio_open (struct commonio_db *db, int mode) goto cleanup_errno; len = strlen (buf); - if (db->ops->fgets (buf + len, - (int) (buflen - len), - db->fp) == NULL) { + if (db->ops->fgets(buf + len, buflen - len, db->fp) == NULL) { goto cleanup_buf; } } diff --git a/lib/gshadow.c b/lib/gshadow.c index 8e9d6c827..3e9e5948d 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -170,9 +170,7 @@ void endsgent (void) buflen *= 2; len = strlen (buf); - if (fgetsx (&buf[len], - (int) (buflen - len), - fp) != &buf[len]) { + if (fgetsx(&buf[len], buflen - len, fp) != &buf[len]) { return NULL; } } diff --git a/lib/setupenv.c b/lib/setupenv.c index ca9b15da3..099112948 100644 --- a/lib/setupenv.c +++ b/lib/setupenv.c @@ -54,7 +54,7 @@ static void read_env_file (const char *filename) if (NULL == fp) { return; } - while (fgets(buf, (int) sizeof(buf), fp) == buf) { + while (fgets(buf, sizeof(buf), fp) == buf) { if (stpsep(buf, "\n") == NULL) break; diff --git a/src/chgpasswd.c b/src/chgpasswd.c index 4035f2d96..8a3baa131 100644 --- a/src/chgpasswd.c +++ b/src/chgpasswd.c @@ -459,7 +459,7 @@ int main (int argc, char **argv) * group entry for each group will be looked up in the appropriate * file (gshadow or group) and the password changed. */ - while (fgets(buf, (int) sizeof(buf), stdin) != NULL) { + while (fgets(buf, sizeof(buf), stdin) != NULL) { line++; if (stpsep(buf, "\n") == NULL) { fprintf (stderr, _("%s: line %d: line too long\n"),