Skip to content

Commit 6e2a462

Browse files
committed
doc-links: lint-ci clean again (seam calls only in seam builds; escape check type)
make -f Makefile.cbm lint-ci failed on code of the checkpoint: - doc_links_msbuild.c: outside a seam build, msb_fail_value_alloc and msb_fail_prop_insert were stubs that return false, so cppcheck reported every condition that calls them as always false or always true (knownConditionTrueFalse, five sites). The calls are now compiled only with CBM_ENABLE_TEST_SEAMS, as the layer's other seams are, and the stubs are gone. - mcp.c: in one configuration of vendored yyjson.h's fallback typedef chain cppcheck takes uint32_t for unsigned short and reports the bounds of the U+E0000 tag block as out of range (compareValueOutOfTypeRangeError). The preview's escape check takes unsigned long, which the standard makes at least 32 bits wide. The product binary is byte-identical before and after. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 91aa8e2 commit 6e2a462

2 files changed

Lines changed: 25 additions & 12 deletions

File tree

‎src/mcp/mcp.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6317,7 +6317,11 @@ static size_t doc_link_scalar(const unsigned char *text, size_t length, uint32_t
63176317
return width;
63186318
}
63196319

6320-
static bool doc_link_visible_escape(uint32_t scalar) {
6320+
/* `unsigned long` (at least 32 bits by the standard), not uint32_t: the
6321+
* vendored yyjson.h has a fallback typedef chain for uint32_t, and an
6322+
* analysis that cannot evaluate it takes uint32_t for a 16-bit type and the
6323+
* tag block's bounds for out of range. */
6324+
static bool doc_link_visible_escape(unsigned long scalar) {
63216325
return scalar < 0x20 || scalar == 0x7F || (scalar >= 0x200B && scalar <= 0x200F) ||
63226326
(scalar >= 0x202A && scalar <= 0x202E) || (scalar >= 0x2066 && scalar <= 0x2069) ||
63236327
(scalar >= 0xE0000 && scalar <= 0xE007F);

‎src/pipeline/doc_links_msbuild.c‎

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,6 @@ static void msb_work(uint64_t n) {
497497
(void)n;
498498
}
499499
static void msb_record(void) {}
500-
static bool msb_fail_value_alloc(void) {
501-
return false;
502-
}
503-
static bool msb_fail_prop_insert(void) {
504-
return false;
505-
}
506500
static bool msb_fail_item_operation(cbm_msb_item_fail_operation_t operation) {
507501
(void)operation;
508502
return false;
@@ -710,7 +704,11 @@ static char *scratch_strndup(msb_eval_t *ev, const char *s, size_t n) {
710704
* old buffers simultaneously until copying has finished and the old one is
711705
* released; neither a replacement nor an unknown value retains history. */
712706
static char *value_alloc(msb_eval_t *ev, size_t n) {
713-
if (n > SIZE_MAX - ev->value_bytes || msb_fail_value_alloc()) {
707+
bool fail = n > SIZE_MAX - ev->value_bytes;
708+
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
709+
fail = fail || msb_fail_value_alloc();
710+
#endif
711+
if (fail) {
714712
ev->oom = true;
715713
return NULL;
716714
}
@@ -786,7 +784,10 @@ static void msb_set(msb_eval_t *ev, const char *name, const char *value) {
786784
if (!k) {
787785
return;
788786
}
789-
if (!msb_fail_prop_insert()) {
787+
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
788+
if (!msb_fail_prop_insert())
789+
#endif
790+
{
790791
msb_work(SKIP_ONE);
791792
cbm_ht_set(ev->props, k, p);
792793
}
@@ -1354,9 +1355,13 @@ static st_value_t *st_make_value(msb_eval_t *ev, const char *text) {
13541355
if (!text)
13551356
return NULL;
13561357
size_t bytes = strlen(text) + 1;
1357-
st_value_t *v = msb_fail_value_alloc()
1358-
? NULL
1359-
: (st_value_t *)cbm_alloc(CBM_MEM_CLASS_OTHER, sizeof(*v) + bytes);
1358+
st_value_t *v = NULL;
1359+
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
1360+
if (!msb_fail_value_alloc())
1361+
#endif
1362+
{
1363+
v = (st_value_t *)cbm_alloc(CBM_MEM_CLASS_OTHER, sizeof(*v) + bytes);
1364+
}
13601365
if (!v) {
13611366
ev->oom = true;
13621367
return NULL;
@@ -1419,22 +1424,26 @@ static void st_write(msb_eval_t *ev, uint32_t key, int domain, const char *text)
14191424
ev->reuse_nodes = ev->view.root[domain];
14201425
effect = st_union(ev, leaf, ev->builder->writes.root[domain], false, domain, phase);
14211426
ev->reuse_nodes = saved_reuse;
1427+
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
14221428
bool is_new = !st_get(ev->builder->writes.root[domain], key);
14231429
if (domain == ST_PROPS && is_new && msb_fail_prop_insert()) {
14241430
st_drop(ev->state, effect);
14251431
effect = st_hold(ev->builder->writes.root[domain]);
14261432
}
1433+
#endif
14271434
if (!st_get(effect, key))
14281435
ev->oom = true;
14291436
}
14301437
ev->reuse_nodes = effect;
14311438
st_node_t *view =
14321439
!ev->oom ? st_union(ev, leaf, ev->view.root[domain], false, domain, phase) : NULL;
14331440
ev->reuse_nodes = saved_reuse;
1441+
#if defined(CBM_ENABLE_TEST_SEAMS) && CBM_ENABLE_TEST_SEAMS
14341442
if (!ev->builder && domain == ST_PROPS && !old && msb_fail_prop_insert()) {
14351443
st_drop(ev->state, view);
14361444
view = st_hold(ev->view.root[domain]);
14371445
}
1446+
#endif
14381447
if (!st_get(view, key))
14391448
ev->oom = true;
14401449
if (!ev->oom) {

0 commit comments

Comments
 (0)