Blob Blame History Raw
From eb26a4fa5432a0bd16b36663d80c7469bce603f8 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Thu, 9 Mar 2017 14:20:57 +0000
Subject: [PATCH 16/26] icotool: Fix const-correctness of handling in and out
 filenames.

This change is mostly straightforward, but I had to change the
prototype of the 'extract_outfile_gen' function so that it doesn't try
to overload the meaning of the 'char **outname_ptr' parameter.  The
(const) input name is placed in a separate parameter.

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
---
 icotool/extract.c |  8 +++-----
 icotool/icotool.h |  4 ++--
 icotool/main.c    | 10 ++++------
 3 files changed, 9 insertions(+), 13 deletions(-)

diff --git a/icotool/extract.c b/icotool/extract.c
index cb8b5dc..8bbf5c7 100644
--- a/icotool/extract.c
+++ b/icotool/extract.c
@@ -95,7 +95,7 @@ static void png_read_mem (png_structp png, png_bytep data, png_size_t size)
 
 
 int
-extract_icons(FILE *in, char *inname, bool listmode, ExtractNameGen outfile_gen, ExtractFilter filter)
+extract_icons(FILE *in, const char *inname, bool listmode, ExtractNameGen outfile_gen, ExtractFilter filter)
 {
 	Win32CursorIconFileDir dir;
 	Win32CursorIconFileDirEntry *entries = NULL;
@@ -191,8 +191,7 @@ extract_icons(FILE *in, char *inname, bool listmode, ExtractNameGen outfile_gen,
 							printf(_(" --hotspot-x=%d --hotspot-y=%d"), entries[c].hotspot_x, entries[c].hotspot_y);
 						printf("\n");
 					} else {
-						outname = inname;
-						out = outfile_gen(&outname, width, height, bit_count, completed);
+						out = outfile_gen(inname, &outname, width, height, bit_count, completed);
 						restore_message_header();
 						set_message_header(outname);
 
@@ -296,8 +295,7 @@ extract_icons(FILE *in, char *inname, bool listmode, ExtractNameGen outfile_gen,
 							goto done;
 						}
 
-						outname = inname;
-						out = outfile_gen(&outname, width, height, bitmap.bit_count, completed);
+						out = outfile_gen(inname, &outname, width, height, bitmap.bit_count, completed);
 						restore_message_header();
 						set_message_header(outname);
 
diff --git a/icotool/icotool.h b/icotool/icotool.h
index ba2fbbd..35c2a45 100644
--- a/icotool/icotool.h
+++ b/icotool/icotool.h
@@ -36,9 +36,9 @@ uint32_t palette_lookup(Palette *palette, uint8_t r, uint8_t g, uint8_t b);
 uint32_t palette_count(Palette *palette);
 
 /* extract.c */
-typedef FILE *(*ExtractNameGen)(char **outname, int width, int height, int bitcount, int index);
+typedef FILE *(*ExtractNameGen)(const char *inname, char **outname, int width, int height, int bitcount, int index);
 typedef bool (*ExtractFilter)(int index, int width, int height, int bitdepth, int palettesize, bool icon, int hotspot_x, int hotspot_y);
-int extract_icons(FILE *in, char *inname, bool listmode, ExtractNameGen outfile_gen, ExtractFilter filter);
+int extract_icons(FILE *in, const char *inname, bool listmode, ExtractNameGen outfile_gen, ExtractFilter filter);
 
 /* create.c */
 typedef FILE *(*CreateNameGen)(char **outname);
diff --git a/icotool/main.c b/icotool/main.c
index 271a5ee..01e62f5 100644
--- a/icotool/main.c
+++ b/icotool/main.c
@@ -127,13 +127,11 @@ create_outfile_gen(char **out)
 }
 
 static FILE *
-extract_outfile_gen(char **outname_ptr, int w, int h, int bc, int i)
+extract_outfile_gen(const char *inname, char **outname_ptr, int w, int h, int bc, int i)
 {
-    char *inname = *outname_ptr;
-
     if (output == NULL || is_directory(output)) {
 	StrBuf *outname;
-	char *inbase;
+	const char *inbase;
 
 	outname = strbuf_new();
 	if (output != NULL) {
@@ -192,7 +190,7 @@ display_help(void)
 }
 
 static bool
-open_file_or_stdin(char *name, FILE **outfile, char **outname)
+open_file_or_stdin(char *name, FILE **outfile, const char **outname)
 {
     if (strcmp(name, "-") == 0) {
         *outfile = stdin;
@@ -216,7 +214,7 @@ main(int argc, char **argv)
     bool extract_mode = false;
     bool create_mode = false;
     FILE *in;
-    char *inname;
+    const char *inname;
     size_t raw_filec = 0;
     char** raw_filev = 0;
 
-- 
2.10.2