]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/snprintf.c
Fix typos in snprintf/vsnprintf emulation code.
[thirdparty/cups.git] / cups / snprintf.c
index 018a3f7aeec05edf6408f5686d103405c2219130..49652e2c43b55abc415fa6538fd01f1dd3b89e4a 100644 (file)
@@ -1,32 +1,18 @@
 /*
- * "$Id: snprintf.c 6649 2007-07-11 21:46:42Z mike $"
+ * snprintf functions for CUPS.
  *
- *   snprintf functions for the Common UNIX Printing System (CUPS).
+ * Copyright © 2007-2019 by Apple Inc.
+ * Copyright © 1997-2007 by Easy Software Products.
  *
- *   Copyright 2007 by Apple Inc.
- *   Copyright 1997-2007 by Easy Software Products.
- *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   which should have been included with this file.  If this file is
- *   file is missing or damaged, see the license at "http://www.cups.org/".
- *
- *   This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- *   _cups_vsnprintf() - Format a string into a fixed size buffer.
- *   _cups_snprintf()  - Format a string into a fixed size buffer.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
  */
 
 /*
  * Include necessary headers...
  */
 
-#include <stdio.h>
-#include <ctype.h>
-#include "string.h"
+#include "string-private.h"
 
 
 #ifndef HAVE_VSNPRINTF
@@ -50,6 +36,7 @@ _cups_vsnprintf(char       *buffer,   /* O - Output buffer */
   char         tformat[100],           /* Temporary format string for sprintf() */
                *tptr,                  /* Pointer into temporary format */
                temp[1024];             /* Buffer for formatted numbers */
+  size_t       templen;                /* Length of "temp" */
   char         *s;                     /* Pointer to string */
   int          slen;                   /* Length of string */
   int          bytes;                  /* Total number of bytes needed */
@@ -185,20 +172,21 @@ _cups_vsnprintf(char       *buffer,       /* O - Output buffer */
              break;
 
            sprintf(temp, tformat, va_arg(ap, double));
+           templen = strlen(temp);
 
-            bytes += (int)strlen(temp);
+            bytes += (int)templen;
 
             if (bufptr)
            {
-             if ((bufptr + strlen(temp)) > bufend)
+             if ((bufptr + templen) > bufend)
              {
-               strncpy(bufptr, temp, (size_t)(bufend - bufptr));
+               strlcpy(bufptr, temp, (size_t)(bufend - bufptr));
                bufptr = bufend;
              }
              else
              {
-               strcpy(bufptr, temp);
-               bufptr += strlen(temp);
+               memcpy(bufptr, temp, templen + 1);
+               bufptr += templen;
              }
            }
            break;
@@ -215,20 +203,21 @@ _cups_vsnprintf(char       *buffer,       /* O - Output buffer */
              break;
 
            sprintf(temp, tformat, va_arg(ap, int));
+           templen = strlen(temp);
 
-            bytes += (int)strlen(temp);
+            bytes += (int)templen;
 
            if (bufptr)
            {
-             if ((bufptr + strlen(temp)) > bufend)
+             if ((bufptr + templen) > bufend)
              {
-               strncpy(bufptr, temp, (size_t)(bufend - bufptr));
+               strlcpy(bufptr, temp, (size_t)(bufend - bufptr));
                bufptr = bufend;
              }
              else
              {
-               strcpy(bufptr, temp);
-               bufptr += strlen(temp);
+               memcpy(bufptr, temp, templen + 1);
+               bufptr += templen;
              }
            }
            break;
@@ -238,20 +227,21 @@ _cups_vsnprintf(char       *buffer,       /* O - Output buffer */
              break;
 
            sprintf(temp, tformat, va_arg(ap, void *));
+           templen = strlen(temp);
 
-            bytes += (int)strlen(temp);
+            bytes += (int)templen;
 
            if (bufptr)
            {
-             if ((bufptr + strlen(temp)) > bufend)
+             if ((bufptr + templen) > bufend)
              {
-               strncpy(bufptr, temp, (size_t)(bufend - bufptr));
+               strlcpy(bufptr, temp, (size_t)(bufend - bufptr));
                bufptr = bufend;
              }
              else
              {
-               strcpy(bufptr, temp);
-               bufptr += strlen(temp);
+               memcpy(bufptr, temp, templen + 1);
+               bufptr += templen;
              }
            }
            break;
@@ -294,13 +284,13 @@ _cups_vsnprintf(char       *buffer,       /* O - Output buffer */
 
              if (sign == '-')
              {
-               strncpy(bufptr, s, (size_t)slen);
+               memcpy(bufptr, s, (size_t)slen);
                memset(bufptr + slen, ' ', (size_t)(width - slen));
              }
              else
              {
                memset(bufptr, ' ', (size_t)(width - slen));
-               strncpy(bufptr + width - slen, s, (size_t)slen);
+               memcpy(bufptr + width - slen, s, (size_t)slen);
              }
 
              bufptr += width;
@@ -356,9 +346,3 @@ _cups_snprintf(char       *buffer,  /* O - Output buffer */
   return (bytes);
 }
 #endif /* !HAVE_SNPRINTF */
-
-
-/*
- * End of "$Id: snprintf.c 6649 2007-07-11 21:46:42Z mike $".
- */
-