Blob Blame History Raw
From 8c5b54454f816e26c52a18870f4ddb3789103313 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 9 Mar 2017 13:49:56 +0000
Subject: [PATCH 11/26] icotool: Use size_t when counting array elements, not
 int.

It's not safe to use int when counting array elements, as on 64 bit
platforms the arrays can overflow a 32 bit int.  (That is, in general.
In this particular case it probably is safe because the original array
is derived from argv.  But it's easier to use the correct type.)

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
---
 icotool/create.c  | 7 ++++---
 icotool/icotool.h | 2 +-
 icotool/main.c    | 2 +-
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/icotool/create.c b/icotool/create.c
index 2e2ccbf..20a0630 100644
--- a/icotool/create.c
+++ b/icotool/create.c
@@ -66,7 +66,7 @@ xfread(void *ptr, size_t size, FILE *stream)
 }
 
 bool
-create_icon(int filec, char **filev, int raw_filec, char** raw_filev, CreateNameGen outfile_gen, bool icon_mode, int32_t hotspot_x, int32_t hotspot_y, int32_t alpha_threshold, int32_t bit_count)
+create_icon(size_t filec, char **filev, size_t raw_filec, char** raw_filev, CreateNameGen outfile_gen, bool icon_mode, int32_t hotspot_x, int32_t hotspot_y, int32_t alpha_threshold, int32_t bit_count)
 {
 	struct {
 		FILE *in;
@@ -87,10 +87,11 @@ create_icon(int filec, char **filev, int raw_filec, char** raw_filev, CreateName
 	Win32CursorIconFileDir dir;
 	FILE *out;
 	char *outname = NULL;
-	uint32_t c, d, x;
+	size_t c;
+	uint32_t d, x;
 	uint32_t dib_start;
 	png_byte ct;
-	int org_filec = filec;
+	size_t org_filec = filec;
 	
 	filec += raw_filec;
 
diff --git a/icotool/icotool.h b/icotool/icotool.h
index ce3bec2..ba2fbbd 100644
--- a/icotool/icotool.h
+++ b/icotool/icotool.h
@@ -42,5 +42,5 @@ int extract_icons(FILE *in, char *inname, bool listmode, ExtractNameGen outfile_
 
 /* create.c */
 typedef FILE *(*CreateNameGen)(char **outname);
-bool create_icon(int filec, char **filev, int raw_filec, char** raw_filev, CreateNameGen outfile_gen, bool icon_mode, int32_t hotspot_x, int32_t hotspot_y, int32_t alpha_threshold, int32_t bit_count);
+bool create_icon(size_t filec, char **filev, size_t raw_filec, char** raw_filev, CreateNameGen outfile_gen, bool icon_mode, int32_t hotspot_x, int32_t hotspot_y, int32_t alpha_threshold, int32_t bit_count);
 #endif
diff --git a/icotool/main.c b/icotool/main.c
index 916fd7f..ec63017 100644
--- a/icotool/main.c
+++ b/icotool/main.c
@@ -217,7 +217,7 @@ main(int argc, char **argv)
     bool create_mode = false;
     FILE *in;
     char *inname;
-    int raw_filec = 0;
+    size_t raw_filec = 0;
     char** raw_filev = 0;
 
     set_program_name(argv[0]);
-- 
2.10.2