Skip to content

Commit 7b3ae85

Browse files
committed
Use va_copy to reuse variable arguments.
1 parent 7cc524f commit 7b3ae85

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

cups/file.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
#include <sys/stat.h>
2020
#include <sys/types.h>
2121
#include <zlib.h>
22+
#ifndef va_copy
23+
# define va_copy(__list1, __list2) ((void)(__list1 = __list2))
24+
#endif
2225

2326

2427
//
@@ -858,7 +861,7 @@ cupsFilePrintf(cups_file_t *fp, // I - CUPS file
858861
const char *format, // I - Printf-style format string
859862
...) // I - Additional args as necessary
860863
{
861-
va_list ap; // Argument list
864+
va_list ap, ap2; // Argument list
862865
ssize_t bytes; // Formatted size
863866

864867

@@ -874,10 +877,9 @@ cupsFilePrintf(cups_file_t *fp, // I - CUPS file
874877
fp->printf_size = 1024;
875878
}
876879

877-
// TODO: Use va_copy instead of calling va_start with the same args
878880
va_start(ap, format);
879-
bytes = vsnprintf(fp->printf_buffer, fp->printf_size, format, ap);
880-
va_end(ap);
881+
va_copy(ap2, ap);
882+
bytes = vsnprintf(fp->printf_buffer, fp->printf_size, format, ap2);
881883

882884
if (bytes >= (ssize_t)fp->printf_size)
883885
{
@@ -893,11 +895,11 @@ cupsFilePrintf(cups_file_t *fp, // I - CUPS file
893895
fp->printf_buffer = temp;
894896
fp->printf_size = (size_t)(bytes + 1);
895897

896-
va_start(ap, format);
897898
bytes = vsnprintf(fp->printf_buffer, fp->printf_size, format, ap);
898-
va_end(ap);
899899
}
900900

901+
va_end(ap);
902+
901903
if (fp->mode == 's')
902904
{
903905
if (!cups_write(fp, fp->printf_buffer, (size_t)bytes))

0 commit comments

Comments
 (0)