md_build_attr_append_substr: Fix +1 allocation error. Fixes #33.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
diff --git a/md4c/md4c.c b/md4c/md4c.c
index 52efc7a..0f3522e 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -1384,13 +1384,14 @@ md_build_attr_append_substr(MD_CTX* ctx, MD_ATTRIBUTE_BUILD* build,
build->substr_alloc = (build->substr_alloc == 0 ? 8 : build->substr_alloc * 2);
new_substr_types = (MD_TEXTTYPE*) realloc(build->substr_types,
- (build->substr_alloc+1) * sizeof(MD_TEXTTYPE));
+ build->substr_alloc * sizeof(MD_TEXTTYPE));
if(new_substr_types == NULL) {
MD_LOG("realloc() failed.");
return -1;
}
+ /* Note +1 to reserve space for final offset (== raw_size). */
new_substr_offsets = (OFF*) realloc(build->substr_offsets,
- build->substr_alloc * sizeof(OFF));
+ (build->substr_alloc+1) * sizeof(OFF));
if(new_substr_offsets == NULL) {
MD_LOG("realloc() failed.");
free(new_substr_types);
diff --git a/test/coverage.txt b/test/coverage.txt
index 7a0ec5a..528069b 100644
--- a/test/coverage.txt
+++ b/test/coverage.txt
@@ -118,6 +118,16 @@ a*b**c*
````````````````````````````````
+### [Issue 33](https://github.com/mity/md4c/issues/33)
+```````````````````````````````` example
+```&&&&&&&&
+.
+<pre><code class="language-&&&&&&&&"></code></pre>
+
+````````````````````````````````
+
+
+
## Code coverage
### `md_is_unicode_whitespace__()`