diff options
-rw-r--r-- | analyzer/pamgetcolor.c | 6 | ||||
-rw-r--r-- | converter/ppm/ppmtompeg/parallel.c | 57 | ||||
-rw-r--r-- | editor/specialty/pnmindex.c | 6 | ||||
-rw-r--r-- | generator/ppmcie.c | 21 | ||||
-rw-r--r-- | lib/util/nstring.c | 64 | ||||
-rw-r--r-- | lib/util/nstring.h | 16 | ||||
-rw-r--r-- | lib/util/vasprintf.c | 13 |
7 files changed, 62 insertions, 121 deletions
diff --git a/analyzer/pamgetcolor.c b/analyzer/pamgetcolor.c index d1ea3799..2bd3050c 100644 --- a/analyzer/pamgetcolor.c +++ b/analyzer/pamgetcolor.c @@ -1,4 +1,8 @@ +#define _C99_SOURCE /* Make sure snprintf() is in stdio.h */ + #include <string.h> +#include <stdio.h> + #include <nstring.h> #include <pm_gamma.h> #include <pam.h> @@ -526,7 +530,7 @@ printColors(struct pam * const pamP, tup = pnm_allocpamtuple(pamP); - pm_snprintf(fmt, sizeof(fmt), "%%%is: %%s\n", cmdLine.maxLbLen); + snprintf(fmt, sizeof(fmt), "%%%is: %%s\n", cmdLine.maxLbLen); for (r = 0; r < cmdLine.regN; ++r) { RegSpec spec; diff --git a/converter/ppm/ppmtompeg/parallel.c b/converter/ppm/ppmtompeg/parallel.c index 0fe635ed..b24764d6 100644 --- a/converter/ppm/ppmtompeg/parallel.c +++ b/converter/ppm/ppmtompeg/parallel.c @@ -12,6 +12,7 @@ * HEADER FILES * *==============*/ +#define _C99_SOURCE /* Make sure snprintf() is in stdio.h */ #define _XOPEN_SOURCE 500 /* Make sure stdio.h contains pclose() */ /* _ALL_SOURCE is needed on AIX to make the C library include the socket services (e.g. define struct sockaddr) @@ -1341,12 +1342,12 @@ startCombineServer(const char * const encoderName, int otherSock; const char * error; - pm_snprintf(command, sizeof(command), - "%s %s -max_machines %d -output_server %s %d %d %s", - encoderName, - debugMachines ? "-debug_machines" : "", - numMachines, masterHostName, masterPortNum, - numInputFiles, paramFileName); + snprintf(command, sizeof(command), + "%s %s -max_machines %d -output_server %s %d %d %s", + encoderName, + debugMachines ? "-debug_machines" : "", + numMachines, masterHostName, masterPortNum, + numInputFiles, paramFileName); machineDebug("MASTER: Starting combine server with shell command '%s'", command); @@ -1383,12 +1384,12 @@ startDecodeServer(const char * const encoderName, int otherSock; const char * error; - pm_snprintf(command, sizeof(command), - "%s %s -max_machines %d -decode_server %s %d %d %s", - encoder_name, - debugMachines ? "-debug_machines" : "", - numMachines, masterHostName, masterPortNum, - numInputFiles, paramFileName); + snprintf(command, sizeof(command), + "%s %s -max_machines %d -decode_server %s %d %d %s", + encoder_name, + debugMachines ? "-debug_machines" : "", + numMachines, masterHostName, masterPortNum, + numInputFiles, paramFileName); machineDebug("MASTER: Starting decode server with shell command '%s'", command); @@ -1681,22 +1682,22 @@ startChildren(struct scheduler * const schedulerP, } --childrenLeftCurrentIoServer; } - pm_snprintf(command, sizeof(command), - "%s %s -l %s %s " - "%s %s -child %s %d %d %d %d %d %d " - "-frames %d %d %s", - rsh, - machineName[childNum], userName[childNum], - beNice ? "nice" : "", - executable[childNum], - debugMachines ? "-debug_machines" : "", - masterHostName, masterPortNum, - remote[childNum] ? ioPortNum[numIoServers-1] : 0, - combinePortNum, decodePortNum, childNum, - remote[childNum] ? 1 : 0, - startFrame, startFrame + nFrames - 1, - remote[childNum] ? - remoteParamFile[childNum] : paramFileName + snprintf(command, sizeof(command), + "%s %s -l %s %s " + "%s %s -child %s %d %d %d %d %d %d " + "-frames %d %d %s", + rsh, + machineName[childNum], userName[childNum], + beNice ? "nice" : "", + executable[childNum], + debugMachines ? "-debug_machines" : "", + masterHostName, masterPortNum, + remote[childNum] ? ioPortNum[numIoServers-1] : 0, + combinePortNum, decodePortNum, childNum, + remote[childNum] ? 1 : 0, + startFrame, startFrame + nFrames - 1, + remote[childNum] ? + remoteParamFile[childNum] : paramFileName ); machineDebug("MASTER: Starting child server " diff --git a/editor/specialty/pnmindex.c b/editor/specialty/pnmindex.c index 2b39e4ec..dcb183ef 100644 --- a/editor/specialty/pnmindex.c +++ b/editor/specialty/pnmindex.c @@ -15,12 +15,14 @@ ============================================================================*/ #define _DEFAULT_SOURCE /* New name for SVID & BSD source defines */ +#define _C99_SOURCE /* Make sure snprintf() is in stdio.h */ #define _XOPEN_SOURCE 500 /* Make sure strdup() is in string.h */ #define _BSD_SOURCE /* Make sure strdup is in string.h */ #include <assert.h> #include <unistd.h> #include <stdarg.h> +#include <stdio.h> #include <errno.h> #include <sys/stat.h> @@ -61,7 +63,7 @@ systemf(const char * const fmt, va_start(varargs, fmt); - pm_vsnprintf(NULL, 0, fmt, varargs, &dryRunLen); + dryRunLen = vsnprintf(NULL, 0, fmt, varargs); va_end(varargs); @@ -82,7 +84,7 @@ systemf(const char * const fmt, va_start(varargs, fmt); - pm_vsnprintf(shellCommand, allocSize, fmt, varargs, &realLen); + realLen = vsnprintf(shellCommand, allocSize, fmt, varargs); assert(realLen == dryRunLen); va_end(varargs); diff --git a/generator/ppmcie.c b/generator/ppmcie.c index 86325ba6..26289c3c 100644 --- a/generator/ppmcie.c +++ b/generator/ppmcie.c @@ -26,8 +26,11 @@ Introduced option to plot 1976 u' v' chromaticities. */ +#define _C99_SOURCE /* Make sure snprintf() is in stdio.h */ + #include <assert.h> #include <math.h> +#include <stdio.h> #include "pm_c_util.h" #include "ppm.h" @@ -1114,15 +1117,15 @@ writeLabel(pixel ** const pixels, PPM_ASSIGN(rgbcolor, maxval, maxval, maxval); - pm_snprintf(sysdesc, sizeof(sysdesc), - "System: %s\n" - "Primary illuminants (X, Y)\n" - " Red: %0.4f, %0.4f\n" - " Green: %0.4f, %0.4f\n" - " Blue: %0.4f, %0.4f\n" - "White point (X, Y): %0.4f, %0.4f", - cs->name, cs->xRed, cs->yRed, cs->xGreen, cs->yGreen, - cs->xBlue, cs->yBlue, cs->xWhite, cs->yWhite); + snprintf(sysdesc, sizeof(sysdesc), + "System: %s\n" + "Primary illuminants (X, Y)\n" + " Red: %0.4f, %0.4f\n" + " Green: %0.4f, %0.4f\n" + " Blue: %0.4f, %0.4f\n" + "White point (X, Y): %0.4f, %0.4f", + cs->name, cs->xRed, cs->yRed, cs->xGreen, cs->yGreen, + cs->xBlue, cs->yBlue, cs->xWhite, cs->yWhite); sysdesc[sizeof(sysdesc)-1] = '\0'; /* for robustness */ ppmd_text(pixels, pixcols, pixrows, maxval, diff --git a/lib/util/nstring.c b/lib/util/nstring.c index 6663ebf0..623fd7b7 100644 --- a/lib/util/nstring.c +++ b/lib/util/nstring.c @@ -1,26 +1,6 @@ /*============================================================================= nstring.c =============================================================================== - - pm_snprintf (and pm_vsnprintf) in this file used to be derived from - 'portable_snprintf' from - http://www.ijs.si/software/snprintf/snprintf-2.2.tar.gz, because not all - system C libraries had snprintf. But in 2013, we extended that snprintf to - implement %f by calling 'snprintf' in the system C library, just to see if - it caused any build failures. As of August 2022, there had been no - complaints of problems caused by this reliance on the system providing - snprintf, so we just made pm_snprintf a wrapper of snprintf for everything. - - Eventually we will remove pm_snprintf and pm_vsnprintf altogether and their - callers will call 'snprintf' and 'vsnprintf' instead - - Note that snprintf is required by the C99 standard. - - The code from which pm_snprintf was formerly derived was protected by - copyright and licensed to the public under GPL. A user in August 2022 noted - that GPL was insufficient for his use of it, making him unable to use - libnetpbm. - Code in this file is contributed to the public domain by its authors. =============================================================================*/ #define _DEFAULT_SOURCE /* New name for SVID & BSD source defines */ @@ -59,46 +39,6 @@ pm_strnlen(const char * const s, -void -pm_vsnprintf(char * const str, - size_t const maxSize, - const char * const fmt, - va_list ap, - size_t * const sizeP) { - - int rc; - - rc = vsnprintf(str, maxSize, fmt, ap); - - assert((size_t)rc == rc); - - *sizeP = (size_t)rc; -} - - - -int -pm_snprintf(char * const dest, - size_t const maxSize, - const char * const fmt, - ...) { - - size_t size; - va_list ap; - - va_start(ap, fmt); - - pm_vsnprintf(dest, maxSize, fmt, ap, &size); - - va_end(ap); - - assert(size <= INT_MAX); - - return size; -} - - - /* When a function that is supposed to return a malloc'ed string cannot get the memory for it, it should return 'pm_strsol'. That has a much better effect on the caller, if the caller doesn't explicitly allow for @@ -144,7 +84,7 @@ pm_asprintf(const char ** const resultP, va_start(varargs, fmt); - pm_vsnprintf(NULL, 0, fmt, varargs, &dryRunLen); + vsnprintf(NULL, 0, fmt, varargs, &dryRunLen); va_end(varargs); @@ -161,7 +101,7 @@ pm_asprintf(const char ** const resultP, va_start(varargs, fmt); - pm_vsnprintf(buffer, allocSize, fmt, varargs, &realLen); + vsnprintf(buffer, allocSize, fmt, varargs, &realLen); assert(realLen == dryRunLen); va_end(varargs); diff --git a/lib/util/nstring.h b/lib/util/nstring.h index 1f03e4f2..7ade39ef 100644 --- a/lib/util/nstring.h +++ b/lib/util/nstring.h @@ -128,8 +128,7 @@ strncaseeq(const char * const comparand, subroutines whose names are similar. They're here because not all standard C libraries have them. - The GNU C library has all of them. All but the oldest standard C libraries - have snprintf(). + The GNU C library has all of them. There are slight differences between the asprintf() family and that found in other libraries: @@ -155,19 +154,6 @@ size_t pm_strnlen(const char * const s, size_t const maxlen); -int -pm_snprintf(char * const dest, - size_t const maxSize, - const char * const fmt, - ...) PM_GNU_PRINTF_ATTR(3,4); - -void -pm_vsnprintf(char * const str, - size_t const maxSize, - const char * const fmt, - va_list ap, - size_t * const sizeP); - const char * pm_strdup(const char * const arg); diff --git a/lib/util/vasprintf.c b/lib/util/vasprintf.c index a947f763..fbca457a 100644 --- a/lib/util/vasprintf.c +++ b/lib/util/vasprintf.c @@ -1,9 +1,11 @@ +#define _C99_SOURCE /* Make sure snprintf() is in stdio.h */ #define _GNU_SOURCE /* Because of conditional compilation, this is GNU source only if the C library is GNU. */ #include <stdlib.h> #include <string.h> +#include <stdio.h> #include "pm_config.h" #include "pm_c_util.h" @@ -36,7 +38,7 @@ pm_vasprintf(const char ** const resultP, simply make two copies of the va_list variable in normal C fashion, but on others you need va_copy, which is a relatively recent invention. In particular, the simple va_list copy - failed on an AMD64 Gcc Linux system in March 2006. + failed on an AMD64 Gcc Linux system in March 2006. So instead, we just allocate 4K and truncate or waste as necessary. @@ -49,14 +51,14 @@ pm_vasprintf(const char ** const resultP, */ size_t const allocSize = 4096; result = malloc(allocSize); - + if (result == NULL) *resultP = pm_strsol; else { size_t realLen; - pm_vsnprintf(result, allocSize, format, varargs, &realLen); - + realLen = vsnprintf(result, allocSize, format, varargs); + if (realLen >= allocSize) strcpy(result + allocSize - 15, "<<<TRUNCATED"); @@ -75,3 +77,6 @@ pm_vasprintf_knows_float(void) { return false; #endif } + + + |