Commit 2cca028906b6484af25e9e04f3273e854b70cb24

Ran Benita 2015-11-19T00:44:27

src/utils: change map_file to not take const string argument map_file() uses PROT_READ, so const seems fitting; however unmap_file calls munmap/free, which do not take const, so an UNCONSTIFY is needed. To avoid the UNCONSTIFY hack, which is likely undefined behavior or some such, just remove the const. Signed-off-by: Ran Benita <ran234@gmail.com>

diff --git a/src/compose/parser.c b/src/compose/parser.c
index 9e936a9..763d29e 100644
--- a/src/compose/parser.c
+++ b/src/compose/parser.c
@@ -493,7 +493,7 @@ do_include(struct xkb_compose_table *table, struct scanner *s,
 {
     FILE *file;
     bool ok;
-    const char *string;
+    char *string;
     size_t size;
     struct scanner new_s;
 
@@ -750,7 +750,7 @@ bool
 parse_file(struct xkb_compose_table *table, FILE *file, const char *file_name)
 {
     bool ok;
-    const char *string;
+    char *string;
     size_t size;
 
     ok = map_file(file, &string, &size);
diff --git a/src/compose/paths.c b/src/compose/paths.c
index 158b4f4..e9d43d7 100644
--- a/src/compose/paths.c
+++ b/src/compose/paths.c
@@ -52,8 +52,9 @@ resolve_name(const char *filename, enum resolve_name_direction direction,
     const char *xlocaledir;
     char path[512];
     FILE *file;
-    const char *string, *end;
+    char *string;
     size_t string_size;
+    const char *end;
     const char *s, *left, *right;
     char *match;
     size_t left_len, right_len, name_len;
diff --git a/src/utils.c b/src/utils.c
index a00b04e..c417106 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -32,7 +32,7 @@
 #include <sys/types.h>
 
 bool
-map_file(FILE *file, const char **string_out, size_t *size_out)
+map_file(FILE *file, char **string_out, size_t *size_out)
 {
     struct stat stat_buf;
     const int fd = fileno(file);
@@ -53,15 +53,15 @@ map_file(FILE *file, const char **string_out, size_t *size_out)
 }
 
 void
-unmap_file(const char *str, size_t size)
+unmap_file(char *str, size_t size)
 {
-    munmap(UNCONSTIFY(str), size);
+    munmap(str, size);
 }
 
 #else
 
 bool
-map_file(FILE *file, const char **string_out, size_t *size_out)
+map_file(FILE *file, char **string_out, size_t *size_out)
 {
     long ret;
     size_t ret_s;
@@ -99,9 +99,9 @@ map_file(FILE *file, const char **string_out, size_t *size_out)
 }
 
 void
-unmap_file(const char *str, size_t size)
+unmap_file(char *str, size_t size)
 {
-    free(UNCONSTIFY(str));
+    free(str);
 }
 
 #endif
diff --git a/src/utils.h b/src/utils.h
index 508435d..4b7e81c 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -179,10 +179,10 @@ msb_pos(uint32_t mask)
 }
 
 bool
-map_file(FILE *file, const char **string_out, size_t *size_out);
+map_file(FILE *file, char **string_out, size_t *size_out);
 
 void
-unmap_file(const char *str, size_t size);
+unmap_file(char *string, size_t size);
 
 #define ARRAY_SIZE(arr) ((sizeof(arr) / sizeof(*(arr))))
 
diff --git a/src/xkbcomp/rules.c b/src/xkbcomp/rules.c
index 94ac547..2a364c8 100644
--- a/src/xkbcomp/rules.c
+++ b/src/xkbcomp/rules.c
@@ -1007,7 +1007,7 @@ xkb_components_from_rules(struct xkb_context *ctx,
     bool ret = false;
     FILE *file;
     char *path;
-    const char *string;
+    char *string;
     size_t size;
     struct matcher *matcher;
 
diff --git a/src/xkbcomp/scanner.c b/src/xkbcomp/scanner.c
index ba8f4e9..1ce6137 100644
--- a/src/xkbcomp/scanner.c
+++ b/src/xkbcomp/scanner.c
@@ -192,7 +192,7 @@ XkbParseFile(struct xkb_context *ctx, FILE *file,
 {
     bool ok;
     XkbFile *xkb_file;
-    const char *string;
+    char *string;
     size_t size;
 
     ok = map_file(file, &string, &size);