md_is_html_block_start_condition: Fix the MD4C_USE_UTF16 mode. The function was calling md_ascii_case_eq() incorrectly with a number of bytes instead of characters. This could lead to invalid memory accesses and/or mis-detection of raw HTML blocks in the special MD4C_USE_UTF16 builds on Windows.
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
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6a7e917..daed7a4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,12 @@
## Next Version (Work in Progress)
+Fixes:
+
+ * Fixed some string length handling in the build mode with `MD4C_USE_UTF16`
+ enabled (Windows-only feature, in order to use `WCHAR` instead of ordinary
+ `char` types).
+
Changes:
* When building MD4C by hand instead of using its CMake-based build, the UTF-8
@@ -23,6 +29,7 @@ Changes:
## Version 0.4.2
Fixes:
+
* [#98](https://github.com/mity/md4c/issues/98):
Fix mis-detection of asterisk-encoded emphasis in some corner cases when
length of the opener and closer differs, as in `**a *b c** d*`.
diff --git a/md4c/md4c.c b/md4c/md4c.c
index d02ae6d..7ba153d 100644
--- a/md4c/md4c.c
+++ b/md4c/md4c.c
@@ -5245,7 +5245,7 @@ md_is_html_block_start_condition(MD_CTX* ctx, OFF beg)
#ifdef X
#undef X
#endif
-#define X(name) { _T(name), sizeof(name)-1 }
+#define X(name) { _T(name), (sizeof(name)-1) / sizeof(CHAR) }
#define Xend { NULL, 0 }
static const TAG t1[] = { X("script"), X("pre"), X("style"), Xend };
@@ -5301,7 +5301,7 @@ md_is_html_block_start_condition(MD_CTX* ctx, OFF beg)
/* Check for type 5: <![CDATA[ */
if(off + 8 < ctx->size) {
- if(md_ascii_eq(STR(off), _T("![CDATA["), 8 * sizeof(CHAR)))
+ if(md_ascii_eq(STR(off), _T("![CDATA["), 8))
return 5;
}
}