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>master
parent
c7e2e6d7b4
commit
2cca028906
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
12
src/utils.c
12
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
|
||||
|
|
|
@ -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))))
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue