-
Notifications
You must be signed in to change notification settings - Fork 169
Description
I came here as a refugee from Discount, and I must say that your library is much better for my needs and doesn't have weird special cases just to be identical to the original John Gruber Perl implementation, which is over 20 years old.
That said, I would love to see a few small changes made. First, I get two compilation warnings. The first is this:
md4c.c: #define OFF_MAX (sizeof(OFF) == 8 ? UINT64_MAX : UINT32_MAX)
which conflicts with something in the OS header files:
usr/include/limits.h: #define OFF_MAX LLONG_MAX /* max value for an off_t */
Since OFF_MAX is not used in the code at all, it seems like it would be easy to just remove it.
The second is this:
md4c.c: ctx.max_ref_def_output = MIN(MIN(16 * (uint64_t)size, (uint64_t)(1024 * 1024)), (uint64_t)SZ_MAX);
The compiler complains that Implicit conversion loses integer precision: 'uint64_t' (aka 'unsigned long long') to 'MD_SIZE' (aka 'unsigned int')
, which is self-explanatory.
Here is a suggestion for a very slight enhancement which isn't necessary, but might help first time users. At first I didn't think your library worked at all, because in my callback function passed to:
int md_html(const MD_CHAR* input, MD_SIZE input_size,
void (*process_output)(const MD_CHAR*, MD_SIZE, void*),
void* userdata, unsigned parser_flags, unsigned renderer_flags);
I was assuming that the string passed to process_output
was null terminated, and it isn't. Yes, it was my bug for assuming that, but it seems like it would be pretty easy to null terminate it in the code via render_verbatim
, which is always the caller. For example, if it can be guaranteed that there's sufficient room, it could copy the character that follows the block, null it, and then restore it upon return.
If that doesn't seem reasonable or there isn't always room for a null character, then a warning in the comment that precedes the declaration of md_html
that alerts callers that the string is not null terminated would be very worthwhile and would not impact the code at all.