Skip to content

Commit

Permalink
Fix snprintf emulation function (Issue #67)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelrsweet committed Feb 1, 2021
1 parent efbea17 commit 2e79749
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES-OPENPRINTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changes in CUPS v2.3.3op2
- Fixed directory/permission defaults for Debian kfreebsd-based systems
(Issue #60, Issue #61)
- Fixed crash bug in `ppdOpen` (Issue #64, Issue #78)
- Fixed regression in `snprintf` emulation function (Issue #67)
- The scheduler's systemd service file now waits for the nslcd service to start
(Issue #69)
- Fixed segfault in help.cgi when searching in man pages (Issue #81)
Expand Down
16 changes: 11 additions & 5 deletions cups/snprintf.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
* snprintf functions for CUPS.
*
* Copyright © 2021 by Michael R Sweet
* Copyright © 2007-2019 by Apple Inc.
* Copyright © 1997-2007 by Easy Software Products.
*
Expand Down Expand Up @@ -81,7 +82,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */
format ++;
width = va_arg(ap, int);

snprintf(tptr, sizeof(tformat) - (tptr - tformat), "%d", width);
/* Note: Can't use snprintf here since we are implementing this function... */
sprintf(tptr, "%d", width);
tptr += strlen(tptr);
}
else
Expand Down Expand Up @@ -113,7 +115,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */
format ++;
prec = va_arg(ap, int);

snprintf(tptr, sizeof(tformat) - (tptr - tformat), "%d", prec);
/* Note: Can't use snprintf here since we are implementing this function... */
sprintf(tptr, "%d", prec);
tptr += strlen(tptr);
}
else
Expand Down Expand Up @@ -171,7 +174,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */
if ((width + 2) > sizeof(temp))
break;

snprintf(temp, sizeof(temp), tformat, va_arg(ap, double));
/* Note: Can't use snprintf here since we are implementing this function... */
sprintf(temp, tformat, va_arg(ap, double));
templen = strlen(temp);

bytes += (int)templen;
Expand Down Expand Up @@ -202,7 +206,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */
if ((width + 2) > sizeof(temp))
break;

snprintf(temp, sizeof(temp), tformat, va_arg(ap, int));
/* Note: Can't use snprintf here since we are implementing this function... */
sprintf(temp, tformat, va_arg(ap, int));
templen = strlen(temp);

bytes += (int)templen;
Expand All @@ -226,7 +231,8 @@ _cups_vsnprintf(char *buffer, /* O - Output buffer */
if ((width + 2) > sizeof(temp))
break;

snprintf(temp, sizeof(temp), tformat, va_arg(ap, void *));
/* Note: Can't use snprintf here since we are implementing this function... */
sprintf(temp, tformat, va_arg(ap, void *));
templen = strlen(temp);

bytes += (int)templen;
Expand Down

0 comments on commit 2e79749

Please sign in to comment.