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.c14
-rw-r--r--src/reader.c2
-rw-r--r--src/serdi.c12
-rw-r--r--src/stack.h2
-rw-r--r--src/string.c8
-rw-r--r--src/string_utils.h8
-rw-r--r--src/uri.c7
-rw-r--r--src/world.c2
-rw-r--r--src/writer.c8
12 files changed, 37 insertions, 44 deletions
diff --git a/src/base64.c b/src/base64.c
index c9e958c2..bcf6b361 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 cdd44ac1..7e0ab2a8 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 5df6cc30..2094432b 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 ea571922..cc0b0a30 100644
--- a/src/node.c
+++ b/src/node.c
@@ -31,15 +31,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*
@@ -107,7 +98,7 @@ serd_node_malloc(size_t n_bytes, SerdNodeFlags flags, SerdNodeType type)
node->n_bytes = 0;
node->flags = flags;
node->type = type;
- assert((intptr_t)node % serd_node_align == 0);
+ assert((uintptr_t)node % serd_node_align == 0u);
return node;
}
@@ -467,6 +458,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
@@ -582,7 +574,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 d2ce61d3..d4c516eb 100644
--- a/src/reader.c
+++ b/src/reader.c
@@ -264,7 +264,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 76496bac..15b97d04 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -206,14 +206,14 @@ main(int argc, char** argv)
SerdEnv* env = serd_env_new(base);
const SerdWriterFlags writer_flags =
- ((ascii ? SERD_STYLE_ASCII : 0) | //
- (full_uris ? (SERD_STYLE_UNQUALIFIED | SERD_STYLE_UNRESOLVED) : 0));
+ ((ascii ? SERD_STYLE_ASCII : 0u) | //
+ (full_uris ? (SERD_STYLE_UNQUALIFIED | SERD_STYLE_UNRESOLVED) : 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,
@@ -228,8 +228,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 = inserter;
diff --git a/src/stack.h b/src/stack.h
index c8716ebd..dbb196ae 100644
--- a/src/stack.h
+++ b/src/stack.h
@@ -48,7 +48,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 b465bf8d..1b106841 100644
--- a/src/string.c
+++ b/src/string.c
@@ -117,16 +117,16 @@ serd_strtod(const char* str, size_t* end)
{
double result = 0.0;
-#define SET_END(index) do { if (end) { *end = index; } } while (0)
+#define SET_END(index) do { if (end) { *end = (size_t)(index); } } while (0)
if (!strcmp(str, "NaN")) {
- SET_END(3);
+ SET_END(3u);
return NAN;
} else if (!strcmp(str, "-INF")) {
- SET_END(4);
+ SET_END(4u);
return -INFINITY;
} else if (!strcmp(str, "INF")) {
- SET_END(3);
+ SET_END(3u);
return INFINITY;
}
diff --git a/src/string_utils.h b/src/string_utils.h
index 7bbfd2b3..4bd36721 100644
--- a/src/string_utils.h
+++ b/src/string_utils.h
@@ -75,7 +75,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 == '=';
}
@@ -120,9 +120,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] & ((1u << (8 - size)) - 1);
+ uint32_t c = utf8[0] & ((1u << (8u - 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;
@@ -137,7 +137,7 @@ parse_utf8_char(const uint8_t* utf8, size_t* size)
return parse_counted_utf8_char(utf8, *size);
default:
*size = 0;
- return 0;
+ return 0u;
}
}
diff --git a/src/uri.c b/src/uri.c
index 7b4b89e4..41a2074c 100644
--- a/src/uri.c
+++ b/src/uri.c
@@ -41,8 +41,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);
}
}
}
@@ -59,7 +60,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 690ef2a4..45f31ea6 100644
--- a/src/world.c
+++ b/src/world.c
@@ -231,7 +231,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 6b7e39b5..99a9beac 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -117,7 +117,7 @@ struct SerdWriterImpl {
SerdLogFunc log_func;
void* log_handle;
WriteContext context;
- unsigned indent;
+ int indent;
char* bprefix;
size_t bprefix_len;
Sep last_sep;
@@ -353,7 +353,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;
@@ -414,7 +414,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);
}
}
@@ -426,7 +426,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);