]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/, src/: Remove useless casts in fgets(3)
authorAlejandro Colomar <alx@kernel.org>
Sun, 21 Jul 2024 16:40:25 +0000 (18:40 +0200)
committerSerge Hallyn <serge@hallyn.com>
Fri, 28 Nov 2025 14:39:37 +0000 (08:39 -0600)
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->cio_fgets(a, (int) (b), c)
+ p->cio_fgets(a, b, c)

@@
expression a, b, c, p;
@@

- p->cio_fgets(a, (int) b, c)
+ p->cio_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 <alx@kernel.org>
lib/setupenv.c
lib/shadow/gshadow/fgetsgent.c
src/chgpasswd.c

index 1485f69e2cd03f67d7b00a9e0c7fe360a29cdf80..1bf8b3a35ef98a5b888813156e982efa29154c85 100644 (file)
@@ -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;
 
index 57e45fb5e189dd01f69736515921b9f8a51aac9c..29ef11b720be039cf52d363d49a5e208645172e9 100644 (file)
@@ -66,9 +66,7 @@ fgetsgent(FILE *fp)
                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;
                }
        }
index 256172f490615eeae297a024b6cdd37504281708..97ad3002931a1222824d983aefdfbae1090b4dd5 100644 (file)
@@ -476,7 +476,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 %jd: line too long\n"),