]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Use size_t for buffer size and make sure it is at least 4 bytes long (Issue #921)
authorMichael R Sweet <msweet@msweet.org>
Sat, 6 Apr 2024 13:37:09 +0000 (09:37 -0400)
committerMichael R Sweet <msweet@msweet.org>
Sat, 6 Apr 2024 13:37:09 +0000 (09:37 -0400)
locale/checkpo.c

index 8e31aeb13b43ddae1f9dd50665ca6ece882e5f7b..7baf33a581bbd4aca2697f38fc7602d5861d79bc 100644 (file)
@@ -24,7 +24,7 @@
  * Local functions...
  */
 
-static char            *abbreviate(const char *s, char *buf, int bufsize);
+static char            *abbreviate(const char *s, char *buf, size_t bufsize);
 static cups_array_t    *collect_formats(const char *id);
 static void            free_formats(cups_array_t *fmts);
 
@@ -292,11 +292,17 @@ main(int  argc,                           /* I - Number of command-line args */
 static char *                          /* O - Abbreviated string */
 abbreviate(const char *s,              /* I - String to abbreviate */
            char       *buf,            /* I - Buffer */
-          int        bufsize)          /* I - Size of buffer */
+          size_t     bufsize)          /* I - Size of buffer */
 {
   char *bufptr;                        /* Pointer into buffer */
 
 
+  if (bufsize < 4)
+  {
+    *buf = '\0';
+    return (buf);
+  }
+
   for (bufptr = buf, bufsize -= 4; *s && bufsize > 0; s ++)
   {
     if (*s == '\n')