From a903dbb3c301f40d196d92b4708d23afab4532f1 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Tue, 19 Apr 2022 21:46:21 -0700 Subject: [PATCH] sfio: remove unnecessary casts Gitlab: #1998 --- lib/sfio/sfclose.c | 2 +- lib/sfio/sfdisc.c | 6 +++--- lib/sfio/sfflsbuf.c | 2 +- lib/sfio/sfnputc.c | 2 +- lib/sfio/sfpkrd.c | 4 ++-- lib/sfio/sfputr.c | 4 ++-- lib/sfio/sfrd.c | 2 +- lib/sfio/sfread.c | 2 +- lib/sfio/sfseek.c | 7 +++---- lib/sfio/sfsetbuf.c | 14 +++++++------- lib/sfio/sfvprintf.c | 2 +- lib/sfio/sfvscanf.c | 2 +- lib/sfio/sfwr.c | 2 +- 13 files changed, 25 insertions(+), 26 deletions(-) diff --git a/lib/sfio/sfclose.c b/lib/sfio/sfclose.c index 27cac9aa7..c3d9dff86 100644 --- a/lib/sfio/sfclose.c +++ b/lib/sfio/sfclose.c @@ -87,7 +87,7 @@ int sfclose(Sfio_t * f) if (f->data && (!local || (f->flags & SF_STRING) || (f->bits & SF_MMAP))) { /* free buffer */ if (f->flags & SF_MALLOC) - data = (void *) f->data; + data = f->data; f->data = NULL; f->size = -1; diff --git a/lib/sfio/sfdisc.c b/lib/sfio/sfdisc.c index ac932a959..0907aa469 100644 --- a/lib/sfio/sfdisc.c +++ b/lib/sfio/sfdisc.c @@ -79,7 +79,7 @@ Sfdisc_t *sfdisc(Sfio_t * f, Sfdisc_t * disc) disc = d->disc; if (d->exceptf) { SFOPEN(f, 0); - if ((*(d->exceptf)) (f, SF_DPOP, (void *) disc, d) < 0) + if ((*(d->exceptf)) (f, SF_DPOP, disc, d) < 0) goto done; SFLOCK(f, 0); } @@ -90,7 +90,7 @@ Sfdisc_t *sfdisc(Sfio_t * f, Sfdisc_t * disc) d = f->disc; if (d && d->exceptf) { SFOPEN(f, 0); - if ((*(d->exceptf)) (f, SF_DPUSH, (void *) disc, d) < 0) + if ((*(d->exceptf)) (f, SF_DPUSH, disc, d) < 0) goto done; SFLOCK(f, 0); } @@ -131,7 +131,7 @@ Sfdisc_t *sfdisc(Sfio_t * f, Sfdisc_t * disc) sfsetbuf(f, NULL, 0); else { unsigned short flags = f->flags; - sfsetbuf(f, (void *) f->data, f->size); + sfsetbuf(f, f->data, f->size); f->flags |= (flags & SF_MALLOC); } } diff --git a/lib/sfio/sfflsbuf.c b/lib/sfio/sfflsbuf.c index bc04f3c92..b584e3f03 100644 --- a/lib/sfio/sfflsbuf.c +++ b/lib/sfio/sfflsbuf.c @@ -77,7 +77,7 @@ int _sfflsbuf(Sfio_t * f, int c) isall = SFISALL(f, isall); if ((w = SFWR(f, data, n, f->disc)) > 0) { if ((n -= w) > 0) /* save unwritten data, then resume */ - memcpy(f->data, (char *) data + w, n); + memcpy(f->data, data + w, n); f->next = f->data + n; if (c < 0 && (!isall || n == 0)) break; diff --git a/lib/sfio/sfnputc.c b/lib/sfio/sfnputc.c index 49895b548..bf76810a7 100644 --- a/lib/sfio/sfnputc.c +++ b/lib/sfio/sfnputc.c @@ -54,7 +54,7 @@ ssize_t sfnputc(Sfio_t * f, int c, size_t n) } for (;;) { /* hard write of data */ - if ((p = SFWRITE(f, (void *) ps, p)) <= 0 || (n -= p) <= 0) { + if ((p = SFWRITE(f, ps, p)) <= 0 || (n -= p) <= 0) { w -= n; goto done; } diff --git a/lib/sfio/sfpkrd.c b/lib/sfio/sfpkrd.c index a2f441ca3..059fc338c 100644 --- a/lib/sfio/sfpkrd.c +++ b/lib/sfio/sfpkrd.c @@ -43,7 +43,7 @@ ssize_t sfpkrd(int fd, void * argbuf, size_t n, int rc, long tm, { ssize_t r; int ntry, t; - char *buf = (char *) argbuf, *endbuf; + char *buf = argbuf, *endbuf; if (rc < 0 && tm < 0 && action <= 0) return read(fd, buf, n); @@ -164,7 +164,7 @@ ssize_t sfpkrd(int fd, void * argbuf, size_t n, int rc, long tm, #ifdef MSG_PEEK if (t & SOCKET_PEEK) { - while ((r = recv(fd, (char *) buf, n, MSG_PEEK)) < 0) { + while ((r = recv(fd, buf, n, MSG_PEEK)) < 0) { if (errno == EINTR) return -1; else if (errno == EAGAIN) { diff --git a/lib/sfio/sfputr.c b/lib/sfio/sfputr.c index 106a38656..31a405ad9 100644 --- a/lib/sfio/sfputr.c +++ b/lib/sfio/sfputr.c @@ -74,7 +74,7 @@ ssize_t sfputr(Sfio_t * f, const char *s, int rc) w += 1; break; } - if ((ps = (uchar *) memccpy(ps, s, '\0', p)) != NULL) + if ((ps = memccpy(ps, s, '\0', p)) != NULL) ps -= 1; else ps = f->next + p; @@ -93,7 +93,7 @@ ssize_t sfputr(Sfio_t * f, const char *s, int rc) if (n > w) n = w; f->next -= n; - (void) SFWRITE(f, (void *) f->next, n); + (void) SFWRITE(f, f->next, n); } SFOPEN(f, 0); diff --git a/lib/sfio/sfrd.c b/lib/sfio/sfrd.c index 471424f50..1454ab96b 100644 --- a/lib/sfio/sfrd.c +++ b/lib/sfio/sfrd.c @@ -136,7 +136,7 @@ ssize_t sfrd(Sfio_t * f, void * buf, size_t n, } else if (SFISNULL(f)) r = 0; else if (f->extent < 0 && (f->flags & SF_SHARE) && rcrv) { /* try peek read */ - r = sfpkrd(f->file, (char *) buf, n, + r = sfpkrd(f->file, buf, n, (rcrv & SF_RC) ? (int) f->getr : -1, -1L, (rcrv & SF_RV) ? 1 : 0); if (r > 0) { diff --git a/lib/sfio/sfread.c b/lib/sfio/sfread.c index 6449c2edd..869f2c0e9 100644 --- a/lib/sfio/sfread.c +++ b/lib/sfio/sfread.c @@ -47,7 +47,7 @@ ssize_t sfread(Sfio_t * f, void * buf, size_t n) f->mode &= ~SF_PEEK; SFMTXRETURN(f, 0); } else { - if ((uchar *) buf != f->next) + if (buf != f->next) SFMTXRETURN(f, (ssize_t) (-1)); f->mode &= ~SF_PEEK; if (f->mode & SF_PKRD) { /* actually read the data now */ diff --git a/lib/sfio/sfseek.c b/lib/sfio/sfseek.c index dc76cf99e..bf31d4349 100644 --- a/lib/sfio/sfseek.c +++ b/lib/sfio/sfseek.c @@ -73,7 +73,7 @@ Sfoff_t sfseek(Sfio_t * f, Sfoff_t p, int type) } if (f->extent < 0) { /* let system call set errno */ - (void) SFSK(f, (Sfoff_t) 0, SEEK_CUR, f->disc); + (void) SFSK(f, 0, SEEK_CUR, f->disc); SFMTXRETURN(f, (Sfoff_t) (-1)); } @@ -102,8 +102,7 @@ Sfoff_t sfseek(Sfio_t * f, Sfoff_t p, int type) f->next = f->data + p; f->here = p; if (p > f->extent) - memclear((char *) (f->data + f->extent), - (int) (p - f->extent)); + memclear(f->data + f->extent, (int)(p - f->extent)); goto done; } @@ -152,7 +151,7 @@ Sfoff_t sfseek(Sfio_t * f, Sfoff_t p, int type) r = p + (type == SEEK_CUR ? s : 0); if (r <= f->here && r >= (f->here - (f->endb - f->data))) { if ((hardseek || (type == SEEK_CUR && p == 0))) { - if ((s = SFSK(f, (Sfoff_t) 0, SEEK_CUR, f->disc)) == f->here || + if ((s = SFSK(f, 0, SEEK_CUR, f->disc)) == f->here || (s >= 0 && !(hardseek & SF_PUBLIC) && (s = SFSK(f, f->here, SEEK_SET, f->disc)) == f->here)) goto near_done; diff --git a/lib/sfio/sfsetbuf.c b/lib/sfio/sfsetbuf.c index 3b3a11c0d..6efbf888c 100644 --- a/lib/sfio/sfsetbuf.c +++ b/lib/sfio/sfsetbuf.c @@ -50,7 +50,7 @@ void *sfsetbuf(Sfio_t * f, void * buf, size_t size) if (size == 0 && buf) { /* special case to get buffer info */ _Sfi = f->val = (f->bits & SF_MMAP) ? (f->endb - f->data) : f->size; - SFMTXRETURN(f, (void *) f->data); + SFMTXRETURN(f, f->data); } /* cleanup actions already done, don't allow write buffering any more */ @@ -117,11 +117,11 @@ void *sfsetbuf(Sfio_t * f, void * buf, size_t size) /* if has discipline, set size by discipline if possible */ if (!HAVE_SYS_STAT_H || disc) { - if ((f->here = SFSK(f, (Sfoff_t) 0, SEEK_CUR, disc)) < 0) + if ((f->here = SFSK(f, 0, SEEK_CUR, disc)) < 0) goto unseekable; else { Sfoff_t e; - if ((e = SFSK(f, (Sfoff_t) 0, SEEK_END, disc)) >= 0) + if ((e = SFSK(f, 0, SEEK_END, disc)) >= 0) f->extent = e > f->here ? e : f->here; (void) SFSK(f, f->here, SEEK_SET, disc); goto setbuf; @@ -133,7 +133,7 @@ void *sfsetbuf(Sfio_t * f, void * buf, size_t size) f->here = -1; else { if (S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) - f->here = SFSK(f, (Sfoff_t) 0, SEEK_CUR, f->disc); + f->here = SFSK(f, 0, SEEK_CUR, f->disc); else f->here = -1; } @@ -210,7 +210,7 @@ void *sfsetbuf(Sfio_t * f, void * buf, size_t size) sf_malloc = 0; if (size > 0 && !buf && !(f->bits & SF_MMAP)) { /* try to allocate a buffer */ if (obuf && size == (size_t) osize && init) { - buf = (void *) obuf; + buf = obuf; obuf = NULL; sf_malloc = (oflags & SF_MALLOC); } @@ -228,7 +228,7 @@ void *sfsetbuf(Sfio_t * f, void * buf, size_t size) if (size == 0 && !(f->flags & SF_STRING) && !(f->bits & SF_MMAP) && (f->mode & SF_READ)) { /* use the internal buffer */ size = sizeof(f->tiny); - buf = (void *) f->tiny; + buf = f->tiny; } /* set up new buffer */ @@ -257,5 +257,5 @@ void *sfsetbuf(Sfio_t * f, void * buf, size_t size) SFOPEN(f, local); - SFMTXRETURN(f, (void *) obuf); + SFMTXRETURN(f, obuf); } diff --git a/lib/sfio/sfvprintf.c b/lib/sfio/sfvprintf.c index b36dfdebc..76f3d4f46 100644 --- a/lib/sfio/sfvprintf.c +++ b/lib/sfio/sfvprintf.c @@ -997,7 +997,7 @@ int sfvprintf(Sfio_t * f, const char *form, va_list args) if ((((flags = f->flags) & SF_SHARE) && !(flags & SF_PUBLIC)) || (n > 0 && (d == (uchar *) data || (flags & SF_LINE)))) - (void) SFWRITE(f, (void *) d, n); + (void) SFWRITE(f, d, n); else f->next += n; diff --git a/lib/sfio/sfvscanf.c b/lib/sfio/sfvscanf.c index 078cf462b..14339f8b5 100644 --- a/lib/sfio/sfvscanf.c +++ b/lib/sfio/sfvscanf.c @@ -533,7 +533,7 @@ int sfvscanf(Sfio_t * f, const char *form, va_list args) if (value) { *val = '\0'; - argv.d = (double) strtod(accept, NULL); + argv.d = strtod(accept, NULL); } if (value) { diff --git a/lib/sfio/sfwr.c b/lib/sfio/sfwr.c index 368309180..a8ea57a02 100644 --- a/lib/sfio/sfwr.c +++ b/lib/sfio/sfwr.c @@ -181,7 +181,7 @@ ssize_t sfwr(Sfio_t * f, const void * buf, size_t n, if (w > 0) { if (!(f->bits & SF_DCDOWN)) { if (f->flags & (SF_APPENDWR | SF_PUBLIC)) - f->here = SFSK(f, (Sfoff_t) 0, SEEK_CUR, dc); + f->here = SFSK(f, 0, SEEK_CUR, dc); else f->here += w; if (f->extent >= 0 && f->here > f->extent) -- 2.40.0