diff options
author | pommicket <pommicket@gmail.com> | 2025-09-15 18:54:37 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2025-09-15 18:54:37 -0400 |
commit | d5cf3acb7a45b7e46bf51dc6a66030d7bc986597 (patch) | |
tree | 357dc594623a3abc2a04d2d516df3bed9406a933 /pom.c | |
parent | 2b519f42fec913763abd0d967301916e763e770a (diff) |
Interpretation tests, various bugfixes
Diffstat (limited to 'pom.c')
-rw-r--r-- | pom.c | 24 |
1 files changed, 16 insertions, 8 deletions
@@ -632,7 +632,7 @@ check_if_key_is_valid(struct parser *parser, const char *key) { bad = (0xfc001bffffffffffU >> c) & 1; } else if (c < 128) { // bitmask of disallowed ASCII characters 64-127 - bad = (0xfc0000017c000001U >> c) & 1; + bad = (0xf800000178000001 >> (c - 64)) & 1; } if (bad) { parser_error(parser, ERROR_KEY_INVALID_CHAR, c, c); @@ -1113,6 +1113,13 @@ static void libc_free(void *udata, void *ptr) { free(ptr); } +static void fix_settings(const pom_settings *in, pom_settings *out) { + *out = in ? *in : (pom_settings){0}; + if (!out->calloc) out->calloc = libc_calloc; + if (!out->realloc) out->realloc = libc_realloc; + if (!out->free) out->free = libc_free; +} + // make single pom_error out of all of parser's errors. static pom_error *parser_make_error(struct parser *parser) { // shouldn't realistically overflow given that we cut off at 1000 errors @@ -1160,10 +1167,7 @@ pom_load(const pom_settings *psettings, const char *filename, if (!read_func) fatal_error("%s called with NULL read function", __func__); pom_settings settings_data = {0}, *settings = &settings_data; - if (psettings) settings_data = *psettings; - if (!settings->calloc) settings->calloc = libc_calloc; - if (!settings->realloc) settings->realloc = libc_realloc; - if (!settings->free) settings->free = libc_free; + fix_settings(psettings, &settings_data); if (error) *error = NULL; // Start by allocating out-of-memory error, so we can just return // it if we run out of memory. @@ -1239,11 +1243,13 @@ read_file(void *file, char *buf, size_t len) { } pom_conf * -pom_load_file(const pom_settings *settings, const char *filename, FILE *file, pom_error **error) { +pom_load_file(const pom_settings *psettings, const char *filename, FILE *file, pom_error **error) { if (!filename) fatal_error("%s called with NULL file name", __func__); if (!file) fatal_error("%s called with NULL file", __func__); + pom_settings settings_data = {0}, *settings = &settings_data; + fix_settings(psettings, &settings_data); pom_conf *conf = pom_load(settings, filename, read_file, file, error); if (ferror(file)) { if (error) { @@ -1257,9 +1263,11 @@ pom_load_file(const pom_settings *settings, const char *filename, FILE *file, po } pom_conf * -pom_load_path(const pom_settings *settings, const char *path, pom_error **error) { +pom_load_path(const pom_settings *psettings, const char *path, pom_error **error) { if (!path) fatal_error("%s called with NULL file name", __func__); + pom_settings settings_data = {0}, *settings = &settings_data; + fix_settings(psettings, &settings_data); FILE *fp = fopen(path, "rb"); if (!fp) { if (error) { @@ -1869,7 +1877,7 @@ pom_conf_get_list(const pom_conf *conf, const char *key) { char *strings = (char *)(list + max_entries+1); const char *p = value_str; while (true) { - while (strchr(" \t\n", *p)) p++; + while (*p == ' ' || *p == '\t' || *p == '\n') p++; const char *end = p; char *out = *entry++ = strings; for (; *end; end++) { |