summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Zern <jzern@google.com>2022-11-15 17:10:26 -0800
committerJames Zern <jzern@google.com>2022-11-15 17:10:26 -0800
commitfad0ece7edec90dbead3cfbe19f2bc9d77a410e2 (patch)
tree717cfda3840eb624ff1393e4d9ddb1ea19aedd68
parent3f73e8f7ac83e97a26346886b529b61809a839f5 (diff)
downloadlibwebp-fad0ece7edec90dbead3cfbe19f2bc9d77a410e2.tar.gz
pnmdec.c: use snprintf instead of sprintf
this is consistent with the rest of the example code Change-Id: Id4c02e16be84fbe21ddc74c9049d8cbda2d875a8
-rw-r--r--imageio/pnmdec.c7
1 files changed, 6 insertions, 1 deletions
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] = ' ';