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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
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);