summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSu_Laus <sulau@freenet.de>2023-02-06 21:23:13 +0100
committerSu_Laus <sulau@freenet.de>2023-02-08 14:14:09 +0100
commit538b8f2935ce8c925a9c2b23c41aa2a8dd65a31f (patch)
tree81c2e32f99368540dc1bf41a541e85c39d984f52
parentafaabc3e50d4e5d80a94143f7e3c997e7e410f68 (diff)
downloadlibtiff-git-538b8f2935ce8c925a9c2b23c41aa2a8dd65a31f.tar.gz
test_ifd_loop_detection: fix Coverity Scan issue CID 1520750: Null pointer dereferences (NULL_RETURNS) line 55.
-rw-r--r--test/test_ifd_loop_detection.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/test/test_ifd_loop_detection.c b/test/test_ifd_loop_detection.c
index 99a749e5..02421f66 100644
--- a/test/test_ifd_loop_detection.c
+++ b/test/test_ifd_loop_detection.c
@@ -36,30 +36,34 @@
#include "tiffio.h"
+/* Compare 'requested_dir_number' with number written in PageName tag
+ * into the IFD to identify that IFD. */
int is_requested_directory(TIFF *tif, int requested_dir_number,
const char *filename)
{
- char *ptr;
+ char *ptr = NULL;
+ char *auxStr = NULL;
if (!TIFFGetField(tif, TIFFTAG_PAGENAME, &ptr))
{
fprintf(stderr, "Can't get TIFFTAG_PAGENAME tag.\n");
return 0;
}
- /* Retrieve directory number from ASCII string */
- char *auxStr = strchr(ptr, ' ');
- int nthIFD;
- nthIFD = atoi(ptr);
-
/* Check for reading errors */
- if (strncmp(auxStr, " th.", 4))
+ if (ptr != NULL)
+ auxStr = strchr(ptr, ' ');
+
+ if (ptr == NULL || auxStr == NULL || strncmp(auxStr, " th.", 4))
{
+ ptr = ptr == NULL ? "(null)" : ptr;
fprintf(stderr,
"Error reading IFD directory number from PageName tag: %s\n",
ptr);
return 0;
}
+ /* Retrieve IFD identification number from ASCII string */
+ const int nthIFD = atoi(ptr);
if (nthIFD == requested_dir_number)
{
return 1;