From 8e9867a3f3e4f5767e9b0be44615bf40fdf597f2 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 8a7ccc5e1..b57cace13 100644 --- a/lib/commonio.c +++ b/lib/commonio.c @@ -656,9 +656,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 e66704a2f..e1f49ba6d 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -160,9 +160,7 @@ sgetsgent(const char *string) 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 70336c3a0..8d355d33c 100644 --- a/lib/setupenv.c +++ b/lib/setupenv.c @@ -55,7 +55,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 a85e47a37..bfb2c7719 100644 --- a/src/chgpasswd.c +++ b/src/chgpasswd.c @@ -460,7 +460,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"),