diff options
author | David Robillard <d@drobilla.net> | 2019-01-07 18:55:35 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-01-07 18:55:35 +0100 |
commit | 9d31b07bbc144da93eb65250ee7cf47611d1ce16 (patch) | |
tree | 83c59c63f86281803ff9e11a033b251e950fbe58 | |
parent | 9b80535334de1a3ca0bf40d2f1109202385148aa (diff) | |
download | serd-9d31b07bbc144da93eb65250ee7cf47611d1ce16.tar.gz serd-9d31b07bbc144da93eb65250ee7cf47611d1ce16.tar.bz2 serd-9d31b07bbc144da93eb65250ee7cf47611d1ce16.zip |
WIP: Fix warningsserd1-warnings
-rw-r--r-- | src/base64.c | 2 | ||||
-rw-r--r-- | src/env.c | 3 | ||||
-rw-r--r-- | src/n3.c | 12 | ||||
-rw-r--r-- | src/node.c | 15 | ||||
-rw-r--r-- | src/reader.c | 3 | ||||
-rw-r--r-- | src/string.c | 8 | ||||
-rw-r--r-- | src/string_utils.h | 14 | ||||
-rw-r--r-- | src/uri.c | 25 | ||||
-rw-r--r-- | src/uri_utils.h | 6 | ||||
-rw-r--r-- | src/world.c | 2 | ||||
-rw-r--r-- | src/writer.c | 14 | ||||
-rw-r--r-- | tests/serd_test.c | 28 |
12 files changed, 75 insertions, 57 deletions
diff --git a/src/base64.c b/src/base64.c index 4171ed22..a8cd780e 100644 --- a/src/base64.c +++ b/src/base64.c @@ -89,7 +89,7 @@ serd_base64_encode(char* const str, static inline uint8_t unmap(const uint8_t in) { - return b64_unmap[in] - 47; + return b64_unmap[in] - 47U; } /** Decode 4 base64 characters to 3 raw bytes. */ @@ -311,7 +311,8 @@ serd_env_expand(const SerdEnv* env, const SerdNode* node) case SERD_URI: return serd_new_resolved_uri_i( serd_node_get_string(node), &env->base_uri); - default: + case SERD_NOTHING: + case SERD_BLANK: break; } return NULL; @@ -81,7 +81,7 @@ read_UCHAR(SerdReader* reader, SerdNode* dest, uint32_t* char_code) } char* endptr = NULL; - const uint32_t code = strtoul((const char*)buf, &endptr, 16); + const uint32_t code = (uint32_t)strtoul((const char*)buf, &endptr, 16); assert(endptr == (char*)buf + length); unsigned size = 0; @@ -281,14 +281,14 @@ read_ws_star(SerdReader* reader) } static inline bool -peek_delim(SerdReader* reader, const char delim) +peek_delim(SerdReader* reader, const uint8_t delim) { read_ws_star(reader); return peek_byte(reader) == delim; } static inline bool -eat_delim(SerdReader* reader, const char delim) +eat_delim(SerdReader* reader, const uint8_t delim) { if (peek_delim(reader, delim)) { eat_byte_safe(reader, delim); @@ -609,7 +609,7 @@ read_IRIREF_scheme(SerdReader* reader, SerdNode* dest) while ((c = peek_byte(reader))) { if (c == '>') { return r_err(reader, SERD_ERR_BAD_SYNTAX, "missing IRI scheme\n"); - } else if (!is_uri_scheme_char(c)) { + } else if (!is_uri_scheme_char((char)c)) { return r_err(reader, SERD_ERR_BAD_SYNTAX, "bad IRI scheme char 0x%X (%c)\n", c, c); } @@ -901,7 +901,7 @@ read_BLANK_NODE_LABEL(SerdReader* reader, SerdNode** dest, bool* ate_dot) } if (fancy_syntax(reader)) { - if (is_digit(buf[reader->bprefix_len + 1])) { + if (is_digit((uint8_t)buf[reader->bprefix_len + 1])) { if ((buf[reader->bprefix_len]) == 'b') { buf[reader->bprefix_len] = 'B'; // Prevent clash reader->seen_genid = true; @@ -1197,7 +1197,7 @@ read_subject(SerdReader* reader, ReadContext ctx, SerdNode** dest, char* s_type) { SerdStatus st = SERD_SUCCESS; bool ate_dot = false; - switch ((*s_type = peek_byte(reader))) { + switch ((*s_type = (char)peek_byte(reader))) { case '[': read_anon(reader, ctx, true, dest); break; @@ -320,7 +320,7 @@ serd_node_compare(const SerdNode* a, const SerdNode* b) } else if (!a || !b) { return (a < b) ? -1 : (a > b) ? 1 : 0; } else if (a->type != b->type) { - return a->type - b->type; + return (a->type < b->type) ? -1 : (a->type > b->type) ? 1 : 0; } const int cmp = strcmp(serd_node_get_string(a), serd_node_get_string(b)); @@ -416,9 +416,10 @@ serd_new_resolved_uri_i(const char* str, const SerdURI* base) static inline bool is_uri_path_char(const char c) { - if (is_alpha(c) || is_digit(c)) { + if (is_alpha((uint8_t)c) || is_digit((uint8_t)c)) { return true; } + switch (c) { case '-': case '.': case '_': case '~': // unreserved case ':': case '@': // pchar @@ -531,7 +532,7 @@ serd_digits(double abs) SerdNode* serd_new_decimal(double d, unsigned frac_digits, const SerdNode* datatype) { - if (isnan(d) || isinf(d)) { + if (!isfinite(d)) { return NULL; } @@ -568,16 +569,16 @@ serd_new_decimal(double d, unsigned frac_digits, const SerdNode* datatype) double frac_part = fabs(d - int_part); if (frac_part < DBL_EPSILON) { *s++ = '0'; - node->n_bytes = (s - buf); + node->n_bytes = (size_t)(s - buf); } else { - uint64_t frac = lround(frac_part * pow(10.0, (int)frac_digits)); + long frac = lround(frac_part * pow(10.0, (int)frac_digits)); s += frac_digits - 1; unsigned i = 0; // Skip trailing zeros for (; i < frac_digits - 1 && !(frac % 10); ++i, --s, frac /= 10) {} - node->n_bytes = (s - buf) + 1; + node->n_bytes = (size_t)(s - buf) + 1; // Write digits from last trailing zero to decimal point for (; i < frac_digits; ++i) { @@ -611,7 +612,7 @@ serd_new_integer(int64_t i, const SerdNode* datatype) ++s; } - node->n_bytes = (s - buf) + 1; + node->n_bytes = (size_t)((s - buf) + 1); // Write integer part (right to left) do { diff --git a/src/reader.c b/src/reader.c index 6113a208..2c13956f 100644 --- a/src/reader.c +++ b/src/reader.c @@ -53,7 +53,8 @@ set_blank_id(SerdReader* reader, SerdNode* node, size_t buf_size) { char* buf = (char*)(node + 1); const char* prefix = reader->bprefix ? (const char*)reader->bprefix : ""; - node->n_bytes = snprintf(buf, buf_size, "%sb%u", prefix, reader->next_id++); + node->n_bytes = + (size_t)snprintf(buf, buf_size, "%sb%u", prefix, reader->next_id++); } size_t diff --git a/src/string.c b/src/string.c index c2466c48..304dec6d 100644 --- a/src/string.c +++ b/src/string.c @@ -93,14 +93,14 @@ serd_strtod(const char* str, size_t* end) const double sign = read_sign(&s); // Parse integer part - for (; is_digit(*s); ++s) { + for (; is_digit((uint8_t)*s); ++s) { result = (result * 10.0) + (*s - '0'); } // Parse fractional part if (*s == '.') { double denom = 10.0; - for (++s; is_digit(*s); ++s) { + for (++s; is_digit((uint8_t)*s); ++s) { result += (*s - '0') / denom; denom *= 10.0; } @@ -111,14 +111,14 @@ serd_strtod(const char* str, size_t* end) ++s; double expt = 0.0; double expt_sign = read_sign(&s); - for (; is_digit(*s); ++s) { + for (; is_digit((uint8_t)*s); ++s) { expt = (expt * 10.0) + (*s - '0'); } result *= pow(10, expt * expt_sign); } if (end) { - *end = s - str; + *end = (size_t)(s - str); } return result * sign; diff --git a/src/string_utils.h b/src/string_utils.h index 717cfda5..4bf723f7 100644 --- a/src/string_utils.h +++ b/src/string_utils.h @@ -30,35 +30,35 @@ static const uint8_t replacement_char[] = { 0xEF, 0xBF, 0xBD }; /** Return true if `c` lies within [`min`...`max`] (inclusive) */ static inline bool -in_range(const char c, const char min, const char max) +in_range(const uint8_t c, const uint8_t min, const uint8_t max) { return (c >= min && c <= max); } /** RFC2234: ALPHA ::= %x41-5A / %x61-7A ; A-Z / a-z */ static inline bool -is_alpha(const char c) +is_alpha(const uint8_t c) { return in_range(c, 'A', 'Z') || in_range(c, 'a', 'z'); } /** RFC2234: DIGIT ::= %x30-39 ; 0-9 */ static inline bool -is_digit(const char c) +is_digit(const uint8_t c) { return in_range(c, '0', '9'); } /** RFC2234: HEXDIG ::= DIGIT / "A" / "B" / "C" / "D" / "E" / "F" */ static inline bool -is_hexdig(const char c) +is_hexdig(const uint8_t c) { return is_digit(c) || in_range(c, 'A', 'F'); } /** Turtle / JSON / C: XDIGIT ::= DIGIT / A-F / a-f */ static inline bool -is_xdigit(const char c) +is_xdigit(const uint8_t c) { return is_hexdig(c) || in_range(c, 'a', 'f'); } @@ -77,7 +77,7 @@ is_space(const char c) /** Return true iff `c` is a valid encoded base64 character. */ static inline bool -is_base64(const char c) +is_base64(const uint8_t c) { return is_alpha(c) || is_digit(c) || c == '+' || c == '/' || c == '='; } @@ -86,7 +86,7 @@ is_base64(const char c) static inline bool is_windows_path(const char* path) { - return is_alpha(path[0]) && (path[1] == ':' || path[1] == '|') + return is_alpha((uint8_t)path[0]) && (path[1] == ':' || path[1] == '|') && (path[2] == '/' || path[2] == '\\'); } @@ -37,8 +37,9 @@ serd_file_uri_parse(const char* uri, char** hostname) return NULL; } if (hostname) { - *hostname = (char*)calloc(path - auth + 1, 1); - memcpy(*hostname, auth, path - auth); + const size_t len = (size_t)(path - auth); + *hostname = (char*)calloc(len + 1, 1); + memcpy(*hostname, auth, len); } } } @@ -48,14 +49,14 @@ serd_file_uri_parse(const char* uri, char** hostname) } SerdBuffer buffer = { NULL, 0 }; - for (const char* s = path; *s; ++s) { + for (const uint8_t* s = (const uint8_t*)path; *s; ++s) { if (*s == '%') { if (*(s + 1) == '%') { serd_buffer_sink("%", 1, 1, &buffer); ++s; } else if (is_hexdig(*(s + 1)) && is_hexdig(*(s + 2))) { - const char code[3] = {*(s + 1), *(s + 2), 0}; - const char c = (char)strtoul((const char*)code, NULL, 16); + const uint8_t code[3] = {*(s + 1), *(s + 2), 0}; + const uint8_t c = (uint8_t)strtoul((const char*)code, NULL, 16); serd_buffer_sink(&c, 1, 1, &buffer); s += 2; } else { @@ -72,12 +73,12 @@ bool serd_uri_string_has_scheme(const char* utf8) { // RFC3986: scheme ::= ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) - if (!utf8 || !is_alpha(utf8[0])) { + if (!utf8 || !is_alpha((uint8_t)utf8[0])) { return false; // Invalid scheme initial character, URI is relative } for (char c; (c = *++utf8) != '\0';) { - if (!is_uri_scheme_char(c)) { + if (!is_uri_scheme_char((uint8_t)c)) { return false; } else if (c == ':') { return true; // End of scheme @@ -99,7 +100,7 @@ serd_uri_parse(const char* utf8, SerdURI* out) */ /* S3.1: scheme ::= ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) */ - if (is_alpha(*ptr)) { + if (is_alpha((uint8_t)*ptr)) { for (char c = *++ptr; true; c = *++ptr) { switch (c) { case '\0': case '/': case '?': case '#': @@ -107,12 +108,12 @@ serd_uri_parse(const char* utf8, SerdURI* out) goto path; // Relative URI (starts with path by definition) case ':': out->scheme.buf = utf8; - out->scheme.len = (ptr++) - utf8; + out->scheme.len = (size_t)((ptr++) - utf8); goto maybe_authority; // URI with scheme case '+': case '-': case '.': continue; default: - if (is_alpha(c) || is_digit(c)) { + if (is_alpha((uint8_t)c) || is_digit((uint8_t)c)) { continue; } } @@ -276,12 +277,12 @@ merge(SerdSlice* base, SerdSlice* path) } while (up > 0 && (--base_last > base->buf)); // Set path prefix - base->len = base_last - base->buf + 1; + base->len = (size_t)(base_last - base->buf + 1); } // Set path suffix path->buf = begin; - path->len = end - begin; + path->len = (size_t)(end - begin); } /// See http://tools.ietf.org/html/rfc3986#section-5.2.2 diff --git a/src/uri_utils.h b/src/uri_utils.h index f734c12e..926aaff3 100644 --- a/src/uri_utils.h +++ b/src/uri_utils.h @@ -66,8 +66,8 @@ uri_rooted_index(const SerdURI* uri, const SerdURI* root) const size_t root_len = uri_path_len(root); size_t last_root_slash = 0; for (size_t i = 0; i < path_len && i < root_len; ++i) { - const uint8_t u = uri_path_at(uri, i); - const uint8_t r = uri_path_at(root, i); + const char u = uri_path_at(uri, i); + const char r = uri_path_at(root, i); differ = differ || u != r; if (r == '/') { @@ -97,7 +97,7 @@ uri_is_under(const SerdURI* uri, const SerdURI* root) } static inline bool -is_uri_scheme_char(const uint8_t c) +is_uri_scheme_char(const char c) { switch (c) { case ':': case '+': case '-': case '.': diff --git a/src/world.c b/src/world.c index f038f031..3d7d02bc 100644 --- a/src/world.c +++ b/src/world.c @@ -121,7 +121,7 @@ serd_world_get_blank(SerdWorld* world) { char* buf = serd_node_buffer(world->blank_node); memset(buf, 0, BLANK_CHARS + 1); - world->blank_node->n_bytes = snprintf( + world->blank_node->n_bytes = (size_t)snprintf( buf, BLANK_CHARS, "b%u", ++world->next_blank_id); return world->blank_node; } diff --git a/src/writer.c b/src/writer.c index 6e3f5d7e..594422ee 100644 --- a/src/writer.c +++ b/src/writer.c @@ -215,7 +215,7 @@ uri_must_escape(const char c) case '^': case '`': case '{': case '|': case '}': return true; default: - return !in_range(c, 0x20, 0x7E); + return !in_range((uint8_t)c, 0x20, 0x7E); } } @@ -303,7 +303,7 @@ write_lname(SerdWriter* writer, const char* utf8, size_t n_bytes) static size_t write_text(SerdWriter* writer, TextContext ctx, - const char* utf8, size_t n_bytes) + const uint8_t* utf8, size_t n_bytes) { size_t len = 0; for (size_t i = 0; i < n_bytes;) { @@ -321,7 +321,7 @@ write_text(SerdWriter* writer, TextContext ctx, break; // Reached end } - const uint8_t in = utf8[i++]; + const char in = utf8[i++]; if (ctx == WRITE_LONG_STRING) { switch (in) { case '\\': len += sink("\\\\", 2, writer); continue; @@ -482,11 +482,11 @@ write_literal(SerdWriter* writer, if (supports_abbrev(writer) && (node->flags & (SERD_HAS_NEWLINE|SERD_HAS_QUOTE))) { sink("\"\"\"", 3, writer); - write_text(writer, WRITE_LONG_STRING, node_str, node->n_bytes); + write_text(writer, WRITE_LONG_STRING, (const uint8_t*)node_str, node->n_bytes); sink("\"\"\"", 3, writer); } else { sink("\"", 1, writer); - write_text(writer, WRITE_STRING, node_str, node->n_bytes); + write_text(writer, WRITE_STRING, (const uint8_t*)node_str, node->n_bytes); sink("\"", 1, writer); } if (lang && serd_node_get_string(lang)) { @@ -501,7 +501,7 @@ write_literal(SerdWriter* writer, // Return true iff `buf` is a valid prefixed name suffix static inline bool -is_name(const char* buf, const size_t len) +is_name(const uint8_t* buf, const size_t len) { // TODO: This is more strict than it should be. for (size_t i = 0; i < len; ++i) { @@ -538,7 +538,7 @@ write_uri_node(SerdWriter* const writer, return sink("()", 2, writer) == 2; } else if (has_scheme && supports_abbrev(writer) && serd_env_qualify_in_place(env, node, &prefix, &suffix) && - is_name(suffix.buf, suffix.len)) { + is_name((const uint8_t*)suffix.buf, suffix.len)) { write_uri_from_node(writer, prefix); sink(":", 1, writer); write_uri(writer, suffix.buf, suffix.len); diff --git a/tests/serd_test.c b/tests/serd_test.c index c009090e..dba92ee9 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -159,13 +159,27 @@ main(void) // Test serd_new_decimal - const double dbl_test_nums[] = { - 0.0, 9.0, 10.0, .01, 2.05, -16.00001, 5.000000005, 0.0000000001, NAN, INFINITY - }; - - const char* dbl_test_strs[] = { - "0.0", "9.0", "10.0", "0.01", "2.05", "-16.00001", "5.00000001", "0.0", NULL, NULL - }; + const double dbl_test_nums[] = {0.0, + 9.0, + 10.0, + .01, + 2.05, + -16.00001, + 5.000000005, + 0.0000000001, + (double)NAN, + (double)INFINITY}; + + const char* dbl_test_strs[] = {"0.0", + "9.0", + "10.0", + "0.01", + "2.05", + "-16.00001", + "5.00000001", + "0.0", + NULL, + NULL}; for (unsigned i = 0; i < sizeof(dbl_test_nums) / sizeof(double); ++i) { SerdNode* node = serd_new_decimal(dbl_test_nums[i], 8, NULL); |