Skip to content

Commit 9f934b2

Browse files
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 <[email protected]>
1 parent da61e23 commit 9f934b2

File tree

4 files changed

+4
-8
lines changed

4 files changed

+4
-8
lines changed

lib/commonio.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,7 @@ int commonio_open (struct commonio_db *db, int mode)
654654
goto cleanup_errno;
655655

656656
len = strlen (buf);
657-
if (db->ops->fgets (buf + len,
658-
(int) (buflen - len),
659-
db->fp) == NULL) {
657+
if (db->ops->fgets(buf + len, buflen - len, db->fp) == NULL) {
660658
goto cleanup_buf;
661659
}
662660
}

lib/gshadow.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,7 @@ void endsgent (void)
170170
buflen *= 2;
171171

172172
len = strlen (buf);
173-
if (fgetsx (&buf[len],
174-
(int) (buflen - len),
175-
fp) != &buf[len]) {
173+
if (fgetsx(&buf[len], buflen - len, fp) != &buf[len]) {
176174
return NULL;
177175
}
178176
}

lib/setupenv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static void read_env_file (const char *filename)
5454
if (NULL == fp) {
5555
return;
5656
}
57-
while (fgets(buf, (int) sizeof(buf), fp) == buf) {
57+
while (fgets(buf, sizeof(buf), fp) == buf) {
5858
if (stpsep(buf, "\n") == NULL)
5959
break;
6060

src/chgpasswd.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ int main (int argc, char **argv)
459459
* group entry for each group will be looked up in the appropriate
460460
* file (gshadow or group) and the password changed.
461461
*/
462-
while (fgets(buf, (int) sizeof(buf), stdin) != NULL) {
462+
while (fgets(buf, sizeof(buf), stdin) != NULL) {
463463
line++;
464464
if (stpsep(buf, "\n") == NULL) {
465465
fprintf (stderr, _("%s: line %d: line too long\n"),

0 commit comments

Comments
 (0)