diff options
author | David Robillard <d@drobilla.net> | 2019-01-07 20:33:42 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-04-13 19:48:23 +0200 |
commit | 2719fc4709d05193aa89557051af1d65a738c4d5 (patch) | |
tree | 18a11d72f789535d79f835f7ad44daa4d1b536b5 | |
parent | 105cc91e8fb7bb1a70e5715dbbbf3f967d508065 (diff) | |
download | serd-2719fc4709d05193aa89557051af1d65a738c4d5.tar.gz serd-2719fc4709d05193aa89557051af1d65a738c4d5.tar.bz2 serd-2719fc4709d05193aa89557051af1d65a738c4d5.zip |
Fix integer conversion warnings
-rw-r--r-- | src/n3.c | 2 | ||||
-rw-r--r-- | src/node.c | 13 | ||||
-rw-r--r-- | src/reader.c | 3 | ||||
-rw-r--r-- | src/string.c | 2 | ||||
-rw-r--r-- | src/uri.c | 11 | ||||
-rw-r--r-- | src/world.c | 2 |
6 files changed, 18 insertions, 15 deletions
@@ -83,7 +83,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; @@ -407,6 +407,7 @@ is_uri_path_char(const char c) if (is_alpha(c) || is_digit(c)) { return true; } + switch (c) { case '-': case '.': case '_': case '~': // unreserved case ':': case '@': // pchar @@ -548,7 +549,7 @@ serd_new_decimal(double d, unsigned frac_digits, const SerdNode* datatype) char* t = s - 1; uint64_t dec = (uint64_t)int_part; do { - *t-- = '0' + (dec % 10); + *t-- = '0' + (char)(dec % 10); } while ((dec /= 10) > 0); @@ -558,16 +559,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 = llround(frac_part * pow(10.0, (int)frac_digits)); + long long frac = llround(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) { @@ -586,7 +587,7 @@ serd_new_integer(int64_t i, const SerdNode* datatype) { const SerdNode* type = datatype ? datatype : &serd_xsd_integer.node; int64_t abs_i = (i < 0) ? -i : i; - const unsigned digits = serd_digits(abs_i); + const unsigned digits = serd_digits((double)abs_i); const size_t type_len = serd_node_total_size(type); const size_t total_len = digits + 2 + type_len; @@ -601,7 +602,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 2d1fbd7e..8b79e2e0 100644 --- a/src/reader.c +++ b/src/reader.c @@ -52,7 +52,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 6a433cdb..52378a6a 100644 --- a/src/string.c +++ b/src/string.c @@ -119,7 +119,7 @@ serd_strtod(const char* str, size_t* end) } if (end) { - *end = s - str; + *end = (size_t)(s - str); } return result * sign; @@ -40,8 +40,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); } } } @@ -110,7 +111,7 @@ 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; @@ -279,12 +280,12 @@ merge(SerdStringView* base, SerdStringView* 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/world.c b/src/world.c index 6209fb0a..2437d83d 100644 --- a/src/world.c +++ b/src/world.c @@ -137,7 +137,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; } |