]> granicus.if.org Git - graphviz/commitdiff
SF_UNBOUND: define as a 'size_t' instead of casting to 'size_t' at every usage
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 9 Oct 2021 19:22:08 +0000 (12:22 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 15 Oct 2021 14:47:02 +0000 (07:47 -0700)
There were also cases missing a cast, which triggered -Wsign-conversion
warnings.

lib/sfio/sfdisc.c
lib/sfio/sfio.h
lib/sfio/sfnew.c
lib/sfio/sfopen.c
lib/sfio/sfsetbuf.c
lib/sfio/sfungetc.c

index 6d1bb1f6eaa1043f136628561a4a332a698c590d..26b3f76534bfca9b13a294a215a3f504b757294c 100644 (file)
@@ -124,7 +124,7 @@ Sfdisc_t *sfdisc(Sfio_t * f, Sfdisc_t * disc)
            SETLOCAL(f);
            f->bits &= (unsigned short)~SF_NULL;        /* turn off /dev/null handling */
            if ((f->bits & SF_MMAP) || (f->mode & SF_INIT))
-               sfsetbuf(f, NULL, (size_t) SF_UNBOUND);
+               sfsetbuf(f, NULL, SF_UNBOUND);
            else if (f->data == f->tiny)
                sfsetbuf(f, NULL, 0);
            else {
index b526c048001e865a0c3ccbebc90730112277d9d1..830738a66979e7a5081d6bab1ebfdcb47efa2c6c 100644 (file)
@@ -26,6 +26,7 @@ extern "C" {
 #   include <sys/types.h>
 #endif // HAVE_SYS_TYPES_H
 
+#include <limits.h>
 #include <stdarg.h>
 #include <stdio.h>
 
@@ -172,7 +173,7 @@ extern "C" {
 #define SF_SETFD       (-1)    /* about to set the file descriptor     */
 
 #define SF_BUFSIZE     8192    /* default buffer size                  */
-#define SF_UNBOUND     (-1)    /* unbounded buffer size                */
+#define SF_UNBOUND SIZE_MAX // unbounded buffer size
 
      extern ssize_t _Sfi;
 
index 2a756f7295e796c820d48949e2f9437a6cb08f01..5b159e07141bf5af91271f48069d062298b9eb3b 100644 (file)
@@ -51,7 +51,7 @@ Sfio_t *sfnew(Sfio_t * oldf, void * buf, size_t size, int file,
                return NULL;
 
            if (f->data
-               && ((flags & SF_STRING) || size != (size_t) SF_UNBOUND)) {
+               && ((flags & SF_STRING) || size != SF_UNBOUND)) {
                if (sflags & SF_MALLOC)
                    free(f->data);
                f->data = NULL;
@@ -88,7 +88,7 @@ Sfio_t *sfnew(Sfio_t * oldf, void * buf, size_t size, int file,
     f->getr = f->tiny[0] = 0;
 
     f->mode |= SF_INIT;
-    if (size != (size_t) SF_UNBOUND) {
+    if (size != SF_UNBOUND) {
        f->size = size;
        f->data = size <= 0 ? NULL : (uchar *) buf;
     }
index ded560ac6a8b0b2a4cb29778dd8acc2691b18175..2b83fa03098f13db61b31f7f44edb9411b5b48d5 100644 (file)
@@ -71,9 +71,7 @@ Sfio_t *sfopen(Sfio_t * f, const char *file, const char *mode)
 
 #endif
     if (sflags & SF_STRING) {
-       f = sfnew(f, (char *) file,
-                 file ? (size_t) strlen(file) : (size_t)
-                 SF_UNBOUND, -1, sflags);
+       f = sfnew(f, (char *)file, file ? strlen(file) : SF_UNBOUND, -1, sflags);
     } else {
        if (!file)
            return NULL;
@@ -114,8 +112,7 @@ Sfio_t *sfopen(Sfio_t * f, const char *file, const char *mode)
 
        /* we may have to reset the file descriptor to its old value */
        oldfd = f ? f->file : -1;
-       if ((f = sfnew(f, NULL, (size_t) SF_UNBOUND, fd, sflags))
-           && oldfd >= 0)
+       if ((f = sfnew(f, NULL, SF_UNBOUND, fd, sflags)) && oldfd >= 0)
             (void) sfsetfd(f, oldfd);
     }
 
index dbfd4807e3f8ac66d2bb4b544a6b25688ac70a78..428237a975b724921a9c9fb3713ade51aada123d 100644 (file)
@@ -123,7 +123,7 @@ void *sfsetbuf(Sfio_t * f, void * buf, size_t size)
 
     /* pure read/string streams must have a valid string */
     if ((f->flags & (SF_RDWR | SF_STRING)) == SF_RDSTR &&
-       (size == (size_t) SF_UNBOUND || !buf))
+       (size == SF_UNBOUND || !buf))
        size = 0;
 
     /* set disc to the first discipline with a seekf */
@@ -208,7 +208,7 @@ void *sfsetbuf(Sfio_t * f, void * buf, size_t size)
 
     /* get buffer space */
   setbuf:
-    if (size == (size_t) SF_UNBOUND) { /* define a default size suitable for block transfer */
+    if (size == SF_UNBOUND) {  /* define a default size suitable for block transfer */
        if (init && osize > 0)
            size = osize;
        else if (f == sfstderr && (f->mode & SF_WRITE))
index 5fa6b74f92255cf241dd386bc667978b1191bcac..a2cd94f47c0b289ec36004f9c253269912b88c13 100644 (file)
@@ -53,8 +53,7 @@ int sfungetc(Sfio_t * f, int c)
 
     /* make a string stream for unget characters */
     if (f->disc != _Sfudisc) {
-       if (!(uf = sfnew(NULL, NULL, (size_t) SF_UNBOUND,
-                        -1, SF_STRING | SF_READ))) {
+       if (!(uf = sfnew(NULL, NULL, SF_UNBOUND, -1, SF_STRING|SF_READ))) {
            c = -1;
            goto done;
        }