]> git.draconx.ca Git - liblbx.git/commitdiff
Use (size_t)-1 instead of SIZE_MAX.
authorNick Bowler <nbowler@draconx.ca>
Tue, 21 Sep 2021 04:53:26 +0000 (00:53 -0400)
committerNick Bowler <nbowler@draconx.ca>
Tue, 21 Sep 2021 04:53:26 +0000 (00:53 -0400)
We do not require the special characteristics of SIZE_MAX (that it be
suitable for use in #if directives), and older library implementations
do not define it.  Outside of the preprocessor, (size_t)-1 is exactly
equivalent so let's just use that instead.

src/error.c
src/lbximg.c
src/pnm.c
src/tools.c

index e46c28faf1b5bb696c4caeed86c169f54f7bb5ec..8071547231d4ee5d59a04fa6397dd54cc2781f79 100644 (file)
@@ -50,9 +50,9 @@ int lbx_error_new(const char *str)
                const char **new;
                size_t size;
 
-               if (user_error_max >= MIN(SIZE_MAX, INT_MAX)/2 - LBX_EUBASE)
+               if (user_error_max >= MIN((size_t)-1, INT_MAX)/2 - LBX_EUBASE)
                        return -1;
-               if (2 * user_error_max >= SIZE_MAX / sizeof *user_errors)
+               if (2 * user_error_max >= (size_t)-1 / sizeof *user_errors)
                        return -1;
 
                size = 2 * user_error_max * sizeof *user_errors;
index 80ffea597ee641684394f12ed229021e64a28d2c..f9975063ff20804d6f0ccbeef6b6f4ce1070e265 100644 (file)
@@ -376,7 +376,7 @@ decode(struct lbx_image *img, FILE *palf, FILE *override, int fmt, char **argv)
        assert(fmt >= 0 && fmt < sizeof formats / sizeof formats[0]);
 
        npixels = img->width;
-       if (img->height && npixels >= SIZE_MAX / img->height) {
+       if (img->height && npixels >= (size_t)-1 / img->height) {
                tool_err(-1, "image too large");
                goto err;
        }
index ace5e1824a5fa3140264876756446e465266c551..de9d2808c1311c25cd37ebe33c5b92c4bec4dff5 100644 (file)
--- a/src/pnm.c
+++ b/src/pnm.c
@@ -154,7 +154,7 @@ static int fprintf_ascii(FILE *f, char *fmt, ...)
        if (rc < 0)
                return -1;
 
-       assert(rc < SIZE_MAX);
+       assert(rc < (size_t)-1);
        buf = malloc(rc+1u);
        if (!buf)
                return -1;
index 200cf9c289e023e20f10681576f4fbf8062e5aac..580580cf1e632c4b560f69334ce1efb57bfe4141 100644 (file)
@@ -56,8 +56,8 @@ const char *tool_invocation(void)
 /* Saturating addition. */
 static size_t add_size(size_t a, size_t b)
 {
-       if (a >= SIZE_MAX - b)
-               return SIZE_MAX;
+       if (a >= (size_t)-1 - b)
+               return (size_t)-1;
        return a + b;
 }
 
@@ -81,7 +81,7 @@ static int vfmsg_internal(FILE *f, int err, const char *fmt, va_list ap)
                totlen = add_size(totlen, errlen);
        }
 
-       if (totlen == SIZE_MAX || totlen > INT_MAX)
+       if (totlen == (size_t)-1 || totlen > INT_MAX)
                return -1;
 
        newfmt = malloc(totlen);