aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/base64.c8
-rw-r--r--src/model.c6
-rw-r--r--src/n3.c16
-rw-r--r--src/node.c12
-rw-r--r--src/reader.c2
-rw-r--r--src/serdi.c10
-rw-r--r--src/stack.h2
-rw-r--r--src/string.c2
-rw-r--r--src/string_utils.h9
-rw-r--r--src/uri.c7
-rw-r--r--src/world.c2
-rw-r--r--src/writer.c17
-rw-r--r--tests/model_test.c4
-rw-r--r--tests/serd_test.c34
14 files changed, 70 insertions, 61 deletions
diff --git a/src/base64.c b/src/base64.c
index 2477ff4b..9fb28019 100644
--- a/src/base64.c
+++ b/src/base64.c
@@ -39,7 +39,7 @@ static const uint8_t b64_map[] =
for decoding, shifted up by 47 to be in the range of printable ASCII.
A '$' is a placeholder for characters not in the base64 alphabet.
*/
-static const char b64_unmap[] =
+static const uint8_t b64_unmap[] =
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$m$$$ncdefghijkl$$$$$$"
"$/0123456789:;<=>?@ABCDEFGH$$$$$$IJKLMNOPQRSTUVWXYZ[\\]^_`ab$$$$"
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
@@ -96,7 +96,7 @@ serd_base64_encode(char* const str,
static inline uint8_t
unmap(const uint8_t in)
{
- return (uint8_t)(b64_unmap[in] - 47);
+ return (uint8_t)(b64_unmap[in] - 47u);
}
/** Decode 4 base64 characters to 3 raw bytes. */
@@ -106,7 +106,7 @@ decode_chunk(const uint8_t in[4], uint8_t out[3])
out[0] = (uint8_t)(((unmap(in[0]) << 2)) | unmap(in[1]) >> 4);
out[1] = (uint8_t)(((unmap(in[1]) << 4) & 0xF0) | unmap(in[2]) >> 2);
out[2] = (uint8_t)(((unmap(in[2]) << 6) & 0xC0) | unmap(in[3]));
- return 1 + (in[2] != '=') + ((in[2] != '=') && (in[3] != '='));
+ return 1U + (in[2] != '=') + ((in[2] != '=') && (in[3] != '='));
}
SerdStatus
@@ -119,7 +119,7 @@ serd_base64_decode(void* buf, size_t* size, const char* str, size_t len)
uint8_t in[] = "====";
size_t n_in = 0;
for (; i < len && n_in < 4; ++n_in) {
- for (; i < len && !is_base64(ustr[i]); ++i) {} // Skip junk
+ for (; i < len && !is_base64(str[i]); ++i) {} // Skip junk
in[n_in] = ustr[i++];
}
if (n_in > 1) {
diff --git a/src/model.c b/src/model.c
index 153561ce..bee9e096 100644
--- a/src/model.c
+++ b/src/model.c
@@ -110,9 +110,9 @@ serd_model_best_index(const SerdModel* model,
{
const bool graph_search = (pat[SERD_GRAPH] != 0);
- const unsigned sig = ((pat[0] ? 1 : 0) * 0x100 +
- (pat[1] ? 1 : 0) * 0x010 +
- (pat[2] ? 1 : 0) * 0x001);
+ const unsigned sig = ((pat[0] ? 1U : 0U) * 0x100 +
+ (pat[1] ? 1U : 0U) * 0x010 +
+ (pat[2] ? 1U : 0U) * 0x001);
SerdOrder good[2] = { (SerdOrder)-1, (SerdOrder)-1 };
diff --git a/src/n3.c b/src/n3.c
index 695ad9aa..6ef3cbf5 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -286,14 +286,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);
@@ -429,9 +429,9 @@ is_PN_CHARS_BASE(const uint32_t c)
static SerdStatus
read_PN_CHARS_BASE(SerdReader* reader, SerdNode* dest)
{
- uint32_t code;
- const int c = peek_byte(reader);
- SerdStatus st = SERD_SUCCESS;
+ uint32_t code = 0;
+ const int c = peek_byte(reader);
+ SerdStatus st = SERD_SUCCESS;
if (is_alpha(c)) {
push_byte(reader, dest, eat_byte_safe(reader, c));
} else if (c == EOF || !(c & 0x80)) {
@@ -459,9 +459,9 @@ is_PN_CHARS(const uint32_t c)
static SerdStatus
read_PN_CHARS(SerdReader* reader, SerdNode* dest)
{
- uint32_t code;
- const int c = peek_byte(reader);
- SerdStatus st = SERD_SUCCESS;
+ uint32_t code = 0;
+ const int c = peek_byte(reader);
+ SerdStatus st = SERD_SUCCESS;
if (is_alpha(c) || is_digit(c) || c == '_' || c == '-') {
push_byte(reader, dest, eat_byte_safe(reader, c));
} else if (c == EOF || !(c & 0x80)) {
diff --git a/src/node.c b/src/node.c
index 36b7644f..b6e5f01d 100644
--- a/src/node.c
+++ b/src/node.c
@@ -29,15 +29,6 @@
#include <stdlib.h>
#include <string.h>
-#ifdef _WIN32
-# ifndef isnan
-# define isnan(x) _isnan(x)
-# endif
-# ifndef isinf
-# define isinf(x) (!_finite(x))
-# endif
-#endif
-
static const size_t serd_node_align = sizeof(SerdNode);
static SerdNode*
@@ -465,6 +456,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
@@ -577,7 +569,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;
}
diff --git a/src/reader.c b/src/reader.c
index c22579e3..47bd1520 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -268,7 +268,7 @@ serd_reader_start_file(SerdReader* reader, const char* uri, bool bulk)
(SerdStreamCloseFunc)fclose,
fd,
name,
- bulk ? SERD_PAGE_SIZE : 1);
+ bulk ? SERD_PAGE_SIZE : 1U);
serd_node_free(name);
return st;
}
diff --git a/src/serdi.c b/src/serdi.c
index 88b89ee8..2d46e300 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -211,13 +211,13 @@ main(int argc, char** argv)
SerdWorld* world = serd_world_new();
SerdEnv* env = serd_env_new(base);
- const SerdWriterFlags writer_flags = (ascii ? SERD_STYLE_ASCII : 0);
+ const SerdWriterFlags writer_flags = (ascii ? SERD_STYLE_ASCII : 0U);
const SerdSerialisationFlags serialisation_flags =
- no_inline ? SERD_NO_INLINE_OBJECTS : 0;
+ no_inline ? SERD_NO_INLINE_OBJECTS : 0U;
SerdByteSink* byte_sink = serd_byte_sink_new(
- (SerdWriteFunc)fwrite, out_fd, bulk_write ? 4096 : 1);
+ (SerdWriteFunc)fwrite, out_fd, bulk_write ? 4096U : 1U);
SerdWriter* writer = serd_writer_new(world,
output_syntax,
@@ -232,8 +232,8 @@ main(int argc, char** argv)
const SerdSink* sink = NULL;
if (use_model) {
const SerdModelFlags flags =
- SERD_INDEX_SPO | (input_has_graphs ? SERD_INDEX_GRAPHS : 0) |
- (no_inline ? 0 : SERD_INDEX_OPS);
+ SERD_INDEX_SPO | (input_has_graphs ? SERD_INDEX_GRAPHS : 0U) |
+ (no_inline ? 0U : SERD_INDEX_OPS);
model = serd_model_new(world, flags);
inserter = serd_inserter_new(model, env, NULL);
sink = serd_inserter_get_sink(inserter);
diff --git a/src/stack.h b/src/stack.h
index 31ed6c09..01e45f52 100644
--- a/src/stack.h
+++ b/src/stack.h
@@ -45,7 +45,7 @@ serd_stack_new(size_t size)
}
static inline bool
-serd_stack_is_empty(SerdStack* stack)
+serd_stack_is_empty(const SerdStack* stack)
{
return stack->size <= SERD_STACK_BOTTOM;
}
diff --git a/src/string.c b/src/string.c
index 77ebd40a..3d3c7dca 100644
--- a/src/string.c
+++ b/src/string.c
@@ -86,7 +86,7 @@ serd_strtod(const char* str, size_t* end)
{
double result = 0.0;
-#define SET_END(index) if (end) { *end = index; }
+#define SET_END(index) if (end) { *end = (size_t)(index); }
if (!strcmp(str, "NaN")) {
SET_END(3);
diff --git a/src/string_utils.h b/src/string_utils.h
index 1accc805..5807d4e2 100644
--- a/src/string_utils.h
+++ b/src/string_utils.h
@@ -76,7 +76,7 @@ is_space(const char c)
}
static inline bool
-is_base64(const char c)
+is_base64(const int c)
{
return is_alpha(c) || is_digit(c) || c == '+' || c == '/' || c == '=';
}
@@ -146,9 +146,9 @@ utf8_num_bytes(const uint8_t c)
static inline uint32_t
parse_counted_utf8_char(const uint8_t* utf8, size_t size)
{
- uint32_t c = utf8[0] & ((1 << (8 - size)) - 1);
+ uint32_t c = utf8[0] & ((1U << (8 - size)) - 1U);
for (size_t i = 1; i < size; ++i) {
- const uint8_t in = utf8[i] & 0x3F;
+ const uint8_t in = utf8[i] & 0x3FU;
c = (c << 6) | in;
}
return c;
@@ -162,7 +162,8 @@ parse_utf8_char(const uint8_t* utf8, size_t* size)
case 1: case 2: case 3: case 4:
return parse_counted_utf8_char(utf8, *size);
default:
- return *size = 0;
+ *size = 0;
+ return 0U;
}
}
diff --git a/src/uri.c b/src/uri.c
index b4f5beb2..fe7de476 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -40,8 +40,9 @@ serd_file_uri_parse(const char* uri, char** hostname)
return NULL;
}
if (hostname) {
- *hostname = (char*)calloc((size_t)(path - auth + 1), 1);
- memcpy(*hostname, auth, (size_t)(path - auth));
+ const size_t len = (size_t)(path - auth);
+ *hostname = (char*)calloc(len + 1, 1);
+ memcpy(*hostname, auth, len);
}
}
}
@@ -58,7 +59,7 @@ serd_file_uri_parse(const char* uri, char** hostname)
++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 char c = (char)strtoul(code, NULL, 16);
serd_buffer_sink(&c, 1, 1, &buffer);
s += 2;
} else {
diff --git a/src/world.c b/src/world.c
index 1c090f8d..48d97da4 100644
--- a/src/world.c
+++ b/src/world.c
@@ -221,7 +221,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 19588c69..f187aefc 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -113,7 +113,7 @@ struct SerdWriterImpl {
SerdLogFunc log_func;
void* log_handle;
WriteContext context;
- unsigned indent;
+ int indent;
char* bprefix;
size_t bprefix_len;
Sep last_sep;
@@ -142,12 +142,13 @@ supports_abbrev(const SerdWriter* writer)
return writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG;
}
-static inline WriteContext*
-anon_stack_top(SerdWriter* writer)
+static inline const WriteContext*
+anon_stack_top(const SerdWriter* writer)
{
assert(!serd_stack_is_empty(&writer->anon_stack));
- return (WriteContext*)(writer->anon_stack.buf
- + writer->anon_stack.size - sizeof(WriteContext));
+ const char* const end = writer->anon_stack.buf + writer->anon_stack.size;
+ const void* const top = end - sizeof(WriteContext);
+ return (const WriteContext*)top;
}
static inline SerdNode*
@@ -319,7 +320,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;
@@ -379,7 +380,7 @@ static void
write_newline(SerdWriter* writer)
{
sink("\n", 1, writer);
- for (unsigned i = 0; i < writer->indent; ++i) {
+ for (int i = 0; i < writer->indent; ++i) {
sink("\t", 1, writer);
}
}
@@ -391,7 +392,7 @@ write_sep(SerdWriter* writer, const Sep sep)
// Adjust indent, but tolerate if it would become negative
writer->indent =
- ((rule->indent >= 0 || writer->indent >= (unsigned)-rule->indent)
+ ((rule->indent >= 0 || writer->indent >= -rule->indent)
? writer->indent + rule->indent
: 0);
diff --git a/tests/model_test.c b/tests/model_test.c
index 37a43b6e..fc893794 100644
--- a/tests/model_test.c
+++ b/tests/model_test.c
@@ -599,7 +599,7 @@ static int
test_triple_index_read(SerdWorld* world, const size_t n_quads)
{
for (unsigned i = 0; i < 6; ++i) {
- SerdModel* model = serd_model_new(world, (1 << i));
+ SerdModel* model = serd_model_new(world, (1U << i));
generate(world, model, n_quads, 0);
assert(!test_read(world, model, 0, n_quads));
serd_model_free(model);
@@ -612,7 +612,7 @@ static int
test_quad_index_read(SerdWorld* world, const size_t n_quads)
{
for (unsigned i = 0; i < 6; ++i) {
- SerdModel* model = serd_model_new(world, (1 << i) | SERD_INDEX_GRAPHS);
+ SerdModel* model = serd_model_new(world, (1U << i) | SERD_INDEX_GRAPHS);
const SerdNode* graph = uri(world, 42);
generate(world, model, n_quads, graph);
assert(!test_read(world, model, graph, n_quads));
diff --git a/tests/serd_test.c b/tests/serd_test.c
index 852c1190..36c27e28 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -220,13 +220,27 @@ test_string_to_double(void)
static void
test_double_to_node(void)
{
- 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);
@@ -719,9 +733,9 @@ test_writer(const char* const path)
}
// Write statements with bad UTF-8 (should be replaced)
- const char bad_str[] = { (char)0xFF, (char)0x90, 'h', 'i', 0 };
- SerdNode* bad_lit = serd_new_string(bad_str);
- SerdNode* bad_uri = serd_new_uri(bad_str);
+ const uint8_t bad_str[] = { 0xFF, 0x90, 'h', 'i', 0 };
+ SerdNode* bad_lit = serd_new_string((const char*)bad_str);
+ SerdNode* bad_uri = serd_new_uri((const char*)bad_str);
assert(!serd_sink_write(iface, 0, s, p, bad_lit, 0));
assert(!serd_sink_write(iface, 0, s, p, bad_uri, 0));
serd_node_free(bad_uri);