aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-07-14 10:26:23 +0200
committerDavid Robillard <d@drobilla.net>2018-07-14 10:26:23 +0200
commit88ac6c757f5a40a604c14775cf11552fa657f0ad (patch)
tree875ac9b954b48750b2548e625b33588883e99643
parent7e10a58373dbbb850c4f4daeb90ce2d9739da441 (diff)
downloadserd-88ac6c757f5a40a604c14775cf11552fa657f0ad.tar.gz
serd-88ac6c757f5a40a604c14775cf11552fa657f0ad.tar.bz2
serd-88ac6c757f5a40a604c14775cf11552fa657f0ad.zip
Fix length of base64 encoded nodes
-rw-r--r--NEWS3
-rw-r--r--src/node.c2
-rw-r--r--tests/serd_test.c3
3 files changed, 6 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 3752c90f..a6ecf2b4 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,6 @@
serd (0.29.3) unstable;
+ * Fix length of base64 encoded nodes
* Clarify errors returned by serd_env_expand()
* Fix reported error when reading statements with only a blank node
* Fix parsing local names that end with escaped dots
@@ -15,7 +16,7 @@ serd (0.29.3) unstable;
* Fix building with MSVC
* Clean up testing code
- -- David Robillard <d@drobilla.net> Sun, 27 May 2018 17:51:33 +0200
+ -- David Robillard <d@drobilla.net> Sat, 14 Jul 2018 10:26:05 +0200
serd (0.28.0) stable;
diff --git a/src/node.c b/src/node.c
index d3136575..655da1d1 100644
--- a/src/node.c
+++ b/src/node.c
@@ -359,7 +359,7 @@ encode_chunk(uint8_t out[4], const uint8_t in[3], size_t n_in)
SerdNode
serd_node_new_blob(const void* buf, size_t size, bool wrap_lines)
{
- const size_t len = ((size + 2) / 3) * 4 + (wrap_lines ? (size / 57) : 0);
+ const size_t len = (size + 2) / 3 * 4 + (wrap_lines * ((size - 1) / 57));
uint8_t* str = (uint8_t*)calloc(1, len + 2);
SerdNode node = { str, len, len, 0, SERD_LITERAL };
for (size_t i = 0, j = 0; i < size; i += 3, j += 4) {
diff --git a/tests/serd_test.c b/tests/serd_test.c
index e312ad04..3c2fb630 100644
--- a/tests/serd_test.c
+++ b/tests/serd_test.c
@@ -206,6 +206,9 @@ main(void)
if (blob.n_bytes != blob.n_chars) {
FAILF("Blob %zu bytes != %zu chars\n",
blob.n_bytes, blob.n_chars);
+ } else if (blob.n_bytes != strlen((const char*)blob.buf)) {
+ FAILF("Blob %zu bytes != length %zu\n",
+ blob.n_bytes, strlen((const char*)blob.buf));
}
size_t out_size;