aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/base64.c8
-rw-r--r--src/model.c6
-rw-r--r--src/n3.c4
-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.c8
12 files changed, 33 insertions, 39 deletions
diff --git a/src/base64.c b/src/base64.c
index 09612a55..97e41e15 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 d9e399f6..dbf19cc8 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 1dc1bc94..a79eafa5 100644
--- a/src/n3.c
+++ b/src/n3.c
@@ -291,14 +291,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);
diff --git a/src/node.c b/src/node.c
index bd08cdda..913789d7 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 5e03679f..2c578ced 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 43964f99..0644ed16 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -202,13 +202,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,
@@ -223,8 +223,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 e2d74769..1460e0c2 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 54a43f0e..969fd734 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 d8bb703a..4864b64a 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 == '=';
}
@@ -148,9 +148,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;
@@ -164,7 +164,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 566690b2..24ac5dcc 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 b003620e..d66297e7 100644
--- a/src/world.c
+++ b/src/world.c
@@ -229,7 +229,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 86733690..cf7a9a6c 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -116,7 +116,7 @@ struct SerdWriterImpl {
SerdLogFunc log_func;
void* log_handle;
WriteContext context;
- unsigned indent;
+ int indent;
char* bprefix;
size_t bprefix_len;
Sep last_sep;
@@ -352,7 +352,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;
@@ -413,7 +413,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);
}
}
@@ -425,7 +425,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);