summaryrefslogtreecommitdiff
path: root/tools/tiffcrop.c
diff options
context:
space:
mode:
authorThomas Bernard <miniupnp@free.fr>2019-01-28 16:10:28 +0100
committerThomas Bernard <miniupnp@free.fr>2019-01-28 16:10:28 +0100
commit5c222ec96c2155e4eb60f9b6b1dace4facaf5c43 (patch)
tree65ebe6096815ed44a1dad4685b14619222530e31 /tools/tiffcrop.c
parenta0e273fdca741b8805e19deeb8019fa42c4e64ba (diff)
downloadlibtiff-git-5c222ec96c2155e4eb60f9b6b1dace4facaf5c43.tar.gz
tiffcrop: shut up clang warnings
make the out filename building a bit more simple and remove the use of strcat()
Diffstat (limited to 'tools/tiffcrop.c')
-rw-r--r--tools/tiffcrop.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/tools/tiffcrop.c b/tools/tiffcrop.c
index edb1addf..bf52229f 100644
--- a/tools/tiffcrop.c
+++ b/tools/tiffcrop.c
@@ -2108,8 +2108,8 @@ update_output_file (TIFF **tiffout, char *mode, int autoindex,
char *outname, unsigned int *page)
{
static int findex = 0; /* file sequence indicator */
+ size_t basename_len;
char *sep;
- char filenum[18];
char export_ext[16];
char exportname[PATH_MAX];
@@ -2120,12 +2120,13 @@ update_output_file (TIFF **tiffout, char *mode, int autoindex,
*tiffout = NULL;
}
- strcpy (export_ext, ".tiff");
- memset (filenum, '\0', sizeof(filenum));
+ memcpy (export_ext, ".tiff", 6);
memset (exportname, '\0', sizeof(exportname));
- /* Leave room for page number portion of the new filename */
- strncpy (exportname, outname, sizeof(exportname) - sizeof(filenum));
+ /* Leave room for page number portion of the new filename :
+ * hyphen + 6 digits + dot + 4 extension characters + null terminator */
+ #define FILENUM_MAX_LENGTH (1+6+1+4+1)
+ strncpy (exportname, outname, sizeof(exportname) - FILENUM_MAX_LENGTH);
if (*tiffout == NULL) /* This is a new export file */
{
if (autoindex)
@@ -2137,8 +2138,9 @@ update_output_file (TIFF **tiffout, char *mode, int autoindex,
*sep = '\0';
}
else
- strncpy (export_ext, ".tiff", 5);
+ memcpy (export_ext, ".tiff", 5);
export_ext[5] = '\0';
+ basename_len = strlen(exportname);
/* MAX_EXPORT_PAGES limited to 6 digits to prevent string overflow of pathname */
if (findex > MAX_EXPORT_PAGES)
@@ -2147,10 +2149,8 @@ update_output_file (TIFF **tiffout, char *mode, int autoindex,
return 1;
}
- snprintf(filenum, sizeof(filenum), "-%03d%.5s", findex, export_ext);
- filenum[sizeof(filenum)-1] = '\0';
- /* We previously assured that there will be space for 'filenum' */
- strcat (exportname, filenum);
+ /* We previously assured that there will be space left */
+ snprintf(exportname + basename_len, sizeof(exportname) - basename_len, "-%03d%.5s", findex, export_ext);
}
exportname[sizeof(exportname) - 1] = '\0';