Skip to content

Commit af81c60

Browse files
guard global safety check setting behind a lock
1 parent ff4f6bf commit af81c60

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/node.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "syntax_extension.h"
88

99
CMARK_DEFINE_LOCK(nextflag)
10+
CMARK_DEFINE_LOCK(safety)
1011

1112
/**
1213
* Expensive safety checks are off by default, but can be enabled
@@ -15,7 +16,20 @@ CMARK_DEFINE_LOCK(nextflag)
1516
static bool enable_safety_checks = false;
1617

1718
void cmark_enable_safety_checks(bool enable) {
19+
CMARK_INITIALIZE_AND_LOCK(safety);
1820
enable_safety_checks = enable;
21+
CMARK_UNLOCK(safety);
22+
}
23+
24+
/**
25+
* Check whether safety checks have been enabled in a function to guard access
26+
* behind a lock.
27+
*/
28+
static bool S_safety_checks_enabled() {
29+
CMARK_INITIALIZE_AND_LOCK(safety);
30+
bool safety_enabled = enable_safety_checks;
31+
CMARK_UNLOCK(safety);
32+
return safety_enabled;
1933
}
2034

2135
static void S_node_unlink(cmark_node *node);
@@ -95,7 +109,7 @@ static bool S_can_contain(cmark_node *node, cmark_node *child) {
95109
return 0;
96110
}
97111

98-
if (enable_safety_checks) {
112+
if (S_safety_checks_enabled()) {
99113
// Verify that child is not an ancestor of node or equal to node.
100114
cmark_node *cur = node;
101115
do {

0 commit comments

Comments
 (0)