Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 12 additions & 15 deletions src/md4c.c
Original file line number Diff line number Diff line change
Expand Up @@ -2520,8 +2520,13 @@ md_free_ref_defs(MD_CTX* ctx)
* cache line.)
*/
struct MD_MARK_tag {
OFF beg;
OFF end;
union {
struct {
OFF beg;
OFF end;
};
void* pointer; // Dummy marks can sometimes store a pointer
};

/* For unresolved openers, 'next' may be used to form a stack of
* unresolved open openers.
Expand Down Expand Up @@ -2653,28 +2658,20 @@ md_mark_stack_pop(MD_CTX* ctx, MD_MARKSTACK* stack)
return top;
}

/* Sometimes, we need to store a pointer into the mark. It is quite rare
* so we do not bother to make MD_MARK use union, and it can only happen
/* Sometimes, we need to store a pointer into the mark. It can only happen
* for dummy marks. */
static inline void
md_mark_store_ptr(MD_CTX* ctx, int mark_index, void* ptr)
{
MD_MARK* mark = &ctx->marks[mark_index];
MD_ASSERT(mark->ch == 'D');

/* Check only members beg and end are misused for this. */
MD_ASSERT(sizeof(void*) <= 2 * sizeof(OFF));
memcpy(mark, &ptr, sizeof(void*));
MD_ASSERT(ctx->marks[mark_index].ch == 'D');
ctx->marks[mark_index].pointer = ptr;
}

static inline void*
md_mark_get_ptr(MD_CTX* ctx, int mark_index)
{
void* ptr;
MD_MARK* mark = &ctx->marks[mark_index];
MD_ASSERT(mark->ch == 'D');
memcpy(&ptr, mark, sizeof(void*));
return ptr;
MD_ASSERT(ctx->marks[mark_index].ch == 'D');
return ctx->marks[mark_index].pointer;
}

static inline void
Expand Down