md_consume_link_reference_definitions: Fix when link references do not compose whole block.
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
diff --git a/md4c/md4c.c b/md4c/md4c.c
index fe6f737..047e7f7 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -1207,7 +1207,7 @@ md_is_link_label(MD_CTX* ctx, const MD_LINE* lines, int n_lines, OFF beg,
int len = 0;
if(CH(off) != _T('['))
- return -1;
+ return FALSE;
off++;
while(line_index < n_lines) {
@@ -1220,7 +1220,7 @@ md_is_link_label(MD_CTX* ctx, const MD_LINE* lines, int n_lines, OFF beg,
contents_end = off + 2;
off += 2;
} else if(CH(off) == _T('[')) {
- return -1;
+ return FALSE;
} else if(CH(off) == _T(']')) {
if(contents_beg < contents_end) {
/* Success. */
@@ -1228,10 +1228,10 @@ md_is_link_label(MD_CTX* ctx, const MD_LINE* lines, int n_lines, OFF beg,
*p_contents_end = contents_end;
*p_end = off+1;
*p_end_line_index = line_index;
- return 0;
+ return TRUE;
} else {
/* Link label must have some non-whitespace contents. */
- return -1;
+ return FALSE;
}
} else {
int codepoint;
@@ -1251,7 +1251,7 @@ md_is_link_label(MD_CTX* ctx, const MD_LINE* lines, int n_lines, OFF beg,
len++;
if(len > 999)
- return -1;
+ return FALSE;
}
line_index++;
@@ -1259,7 +1259,7 @@ md_is_link_label(MD_CTX* ctx, const MD_LINE* lines, int n_lines, OFF beg,
off = lines[line_index].beg;
}
- return -1;
+ return FALSE;
}
static int
@@ -1269,7 +1269,7 @@ md_is_link_destination_A(MD_CTX* ctx, OFF beg, OFF max_end, OFF* p_end,
OFF off = beg;
if(off >= max_end || CH(off) != _T('<'))
- return -1;
+ return FALSE;
off++;
while(off < max_end) {
@@ -1279,20 +1279,20 @@ md_is_link_destination_A(MD_CTX* ctx, OFF beg, OFF max_end, OFF* p_end,
}
if(ISWHITESPACE(off) || CH(off) == _T('<'))
- return -1;
+ return FALSE;
if(CH(off) == _T('>')) {
/* Success. */
*p_contents_beg = beg+1;
*p_contents_end = off;
*p_end = off+1;
- return 0;
+ return TRUE;
}
off++;
}
- return -1;
+ return FALSE;
}
static int
@@ -1315,40 +1315,40 @@ md_is_link_destination_B(MD_CTX* ctx, OFF beg, OFF max_end, OFF* p_end,
* but only if they are not nested. */
if(CH(off) == _T('(')) {
if(in_parentheses)
- return -1;
+ return FALSE;
else
in_parentheses = 1;
} else if(CH(off) == _T(')')) {
if(in_parentheses)
in_parentheses = 0;
else
- return -1;
+ return FALSE;
}
off++;
}
if(in_parentheses || off == beg)
- return -1;
+ return FALSE;
/* Success. */
*p_contents_beg = beg;
*p_contents_end = off;
*p_end = off;
- return 0;
+ return TRUE;
}
static int
md_is_link_destination(MD_CTX* ctx, OFF beg, OFF max_end, OFF* p_end,
OFF* p_contents_beg, OFF* p_contents_end)
{
- if(md_is_link_destination_A(ctx, beg, max_end, p_end, p_contents_beg, p_contents_end) == 0)
- return 0;
+ if(md_is_link_destination_A(ctx, beg, max_end, p_end, p_contents_beg, p_contents_end))
+ return TRUE;
- if(md_is_link_destination_B(ctx, beg, max_end, p_end, p_contents_beg, p_contents_end) == 0)
- return 0;
+ if(md_is_link_destination_B(ctx, beg, max_end, p_end, p_contents_beg, p_contents_end))
+ return TRUE;
- return -1;
+ return FALSE;
}
static int
@@ -1366,7 +1366,7 @@ md_is_link_title(MD_CTX* ctx, const MD_LINE* lines, int n_lines, OFF beg,
if(off >= lines[line_index].end && ISNEWLINE(off)) {
line_index++;
if(line_index >= n_lines)
- return -1;
+ return FALSE;
off = lines[line_index].beg;
}
@@ -1377,7 +1377,7 @@ md_is_link_title(MD_CTX* ctx, const MD_LINE* lines, int n_lines, OFF beg,
case _T('"'): closer_char = _T('"'); break;
case _T('\''): closer_char = _T('\''); break;
case _T('('): closer_char = _T(')'); break;
- default: return -1;
+ default: return FALSE;
}
off++;
@@ -1394,7 +1394,7 @@ md_is_link_title(MD_CTX* ctx, const MD_LINE* lines, int n_lines, OFF beg,
*p_contents_end = off;
*p_end = off+1;
*p_end_line_index = line_index;
- return 0;
+ return TRUE;
}
off++;
@@ -1403,7 +1403,7 @@ md_is_link_title(MD_CTX* ctx, const MD_LINE* lines, int n_lines, OFF beg,
line_index++;
}
- return -1;
+ return FALSE;
}
/* Allocate new buffer, and fill it with copy of the string between
@@ -1477,15 +1477,15 @@ md_is_link_reference_definition(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
int ret = 0;
/* Link label. */
- if(md_is_link_label(ctx, lines, n_lines, lines[0].beg,
+ if(!md_is_link_label(ctx, lines, n_lines, lines[0].beg,
&off, &label_contents_line_index, &line_index,
- &label_contents_beg, &label_contents_end) != 0)
- return 0;
+ &label_contents_beg, &label_contents_end))
+ return FALSE;
label_is_multiline = (label_contents_line_index != line_index);
/* Colon. */
if(off >= lines[line_index].end || CH(off) != _T(':'))
- return 0;
+ return FALSE;
off++;
/* Optional white space with up to one line break. */
@@ -1494,20 +1494,21 @@ md_is_link_reference_definition(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
if(off >= lines[line_index].end && ISNEWLINE(off)) {
line_index++;
if(line_index >= n_lines)
- return 0;
+ return FALSE;
off = lines[line_index].beg;
}
/* Link destination. */
- if(md_is_link_destination(ctx, off, lines[line_index].end,
- &off, &dest_contents_beg, &dest_contents_end) != 0)
- return 0;
+ if(!md_is_link_destination(ctx, off, lines[line_index].end,
+ &off, &dest_contents_beg, &dest_contents_end))
+ return FALSE;
/* (Optional) title. Note we interpret it as an title only if nothing
* more follows on its last line. */
if(md_is_link_title(ctx, lines + line_index, n_lines - line_index, off,
- &off, &title_contents_line_index, &tmp_line_index, &title_contents_beg, &title_contents_end) == 0
- && off >= lines[line_index].end)
+ &off, &title_contents_line_index, &tmp_line_index,
+ &title_contents_beg, &title_contents_end)
+ && off >= lines[line_index + tmp_line_index].end)
{
title_is_multiline = (tmp_line_index != title_contents_line_index);
title_contents_line_index += line_index;
@@ -1520,7 +1521,7 @@ md_is_link_reference_definition(MD_CTX* ctx, const MD_LINE* lines, int n_lines)
/* Nothing more can follow on the last line. */
if(off < lines[line_index].end)
- return 0;
+ return FALSE;
/* Store the link reference definition. */
def = (MD_LINK_REF_DEF*) malloc(sizeof(MD_LINK_REF_DEF));
@@ -3527,7 +3528,7 @@ md_consume_link_reference_definitions(MD_CTX* ctx)
ctx->n_block_bytes -= sizeof(MD_BLOCK);
} else {
/* Remove just some initial lines from the block. */
- memmove(lines, lines + n, n_lines - n);
+ memmove(lines, lines + n, (n_lines - n) * sizeof(MD_LINE));
ctx->current_block->n_lines -= n;
ctx->n_block_bytes -= n * sizeof(MD_LINE);
}