From fad0ece7edec90dbead3cfbe19f2bc9d77a410e2 Mon Sep 17 00:00:00 2001 From: James Zern Date: Tue, 15 Nov 2022 17:10:26 -0800 Subject: [PATCH] pnmdec.c: use snprintf instead of sprintf this is consistent with the rest of the example code Change-Id: Id4c02e16be84fbe21ddc74c9049d8cbda2d875a8 --- imageio/pnmdec.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/imageio/pnmdec.c b/imageio/pnmdec.c index 2db007d7..0d592c32 100644 --- a/imageio/pnmdec.c +++ b/imageio/pnmdec.c @@ -20,6 +20,10 @@ #include "webp/encode.h" #include "./imageio_util.h" +#if defined(_MSC_VER) && _MSC_VER < 1900 +#define snprintf _snprintf +#endif + typedef enum { WIDTH_FLAG = 1 << 0, HEIGHT_FLAG = 1 << 1, @@ -111,8 +115,9 @@ static size_t ReadPAMFields(PNMInfo* const info, size_t off) { break; } else { static const char kEllipsis[] = " ..."; + const size_t kLen = strlen(kEllipsis) + 1; // +1 = trailing \0 int i; - if (out_size > 20) sprintf(out + 20 - strlen(kEllipsis), kEllipsis); + if (out_size > 20) snprintf(out + 20 - kLen, kLen, kEllipsis); for (i = 0; i < (int)strlen(out); ++i) { // isprint() might trigger a "char-subscripts" warning if given a char. if (!isprint((int)out[i])) out[i] = ' ';