From def37b7d2c8dbe275385017120e9ff73322e0528 Mon Sep 17 00:00:00 2001
From: Andrey Kiselev <[EMAIL REDACTED]>
Date: Fri, 5 Sep 2008 06:45:09 +0000
Subject: [PATCH] Use dynamically allocated array instead of static when
constructing output file names.
---
tools/tiffsplit.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/tools/tiffsplit.c b/tools/tiffsplit.c
index 117b4a02..10baa9de 100644
--- a/tools/tiffsplit.c
+++ b/tools/tiffsplit.c
@@ -1,4 +1,4 @@
-/* $Id: tiffsplit.c,v 1.14.2.1 2008-09-03 07:48:25 dron Exp $ */
+/* $Id: tiffsplit.c,v 1.14.2.2 2008-09-05 06:45:09 dron Exp $ */
/*
* Copyright (c) 1992-1997 Sam Leffler
@@ -45,6 +45,8 @@ extern int getopt(int, char**, char*);
#define PATH_LENGTH 8192
+static const char TIFF_SUFFIX[] = ".tif";
+
static char fname[PATH_LENGTH];
static int tiffcp(TIFF*, TIFF*);
@@ -69,10 +71,19 @@ main(int argc, char* argv[])
in = TIFFOpen(argv[1], "r");
if (in != NULL) {
do {
- char path[PATH_LENGTH];
+ size_t path_len;
+ char *path;
+
newfilename();
- snprintf(path, sizeof(path), "%s.tif", fname);
+
+ path_len = strlen(fname) + sizeof(TIFF_SUFFIX);
+ path = (char *) _TIFFmalloc(path_len);
+ strncpy(path, fname, path_len);
+ path[path_len - 1] = '\0';
+ strncat(path, TIFF_SUFFIX, path_len - strlen(path) - 1);
out = TIFFOpen(path, TIFFIsBigEndian(in)?"wb":"wl");
+ _TIFFfree(path);
+
if (out == NULL)
return (-2);
if (!tiffcp(in, out))