Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
fix(cli): read gate thresholds through cbm_env_long
Martin Vogelcb62f63739e9
diff --git a/src/cli/cli.c b/src/cli/cli.cindex cbbdec068..9a1dd25b9 100644--- a/src/cli/cli.c+++ b/src/cli/cli.c@@ -160,21 +160,14 @@ int cbm_cli_exit_status_after_maintenance(int exit_status, bool maintenance_canc}/* One override, parsed strictly: a typo must not silently disable a gate, so- * anything that is not a whole number falls back to the documented default. */+ * anything that is not a whole number falls back to the documented default.+ * cbm_env_long is the project's strict reader for exactly this case: it+ * refuses empty text, blanks, trailing junk and values too large for a long+ * (strtol would clamp those to LONG_MAX, a ceiling no run can exceed), and it+ * reads the Windows environment the same way every other setting does. */static long cli_gate_threshold(const char *name, long fallback) {- const char *raw = getenv(name);- if (!raw || !raw[0]) {- return fallback;- }- char *end = NULL;- errno = 0;- long value = strtol(raw, &end, 10);- /* Overflow clamps to LONG_MAX with the whole string consumed, which would- * read as a ceiling no run can exceed: the one typo that disables a gate. */- if (errno == ERANGE || end == raw || *end != '\0') {- return fallback;- }- return value;+ long value = 0;+ return cbm_env_long(name, &value) ? value : fallback;}/* The contract is opt-in. Unset, empty, or "0" leaves the historical 0/1diff --git a/tests/test_cli.c b/tests/test_cli.cindex 54dc5ed29..ec898e99d 100644--- a/tests/test_cli.c+++ b/tests/test_cli.c@@ -18482,10 +18482,14 @@ TEST(cli_index_exit_unreadable_threshold_falls_back_to_default) {cli_gate_env_t saved = cli_gate_env_clear();const char *twenty_percent = "{\"status\":\"ok\",\"files_indexed\":100,""\"parse_partial_count\":20,\"parse_unusable_count\":0}";- /* The last one overflows long: strtol clamps it to LONG_MAX with the- * whole string consumed, a ceiling no run could exceed. */+ /* The numeric-looking values carry 50, not the default 10: a reader that+ * wrongly accepted one would raise the ceiling above the 20% payload and+ * pass the run, so every refusal is visible. " 10" could not show that,+ * and plain strtol does accept a leading blank. The last one overflows+ * long: strtol clamps it to LONG_MAX with the whole string consumed, a+ * ceiling no run could exceed. */const char *unreadable[] = {- "abc", "1O", "10pct", " 10", "10 ", "", "1e1", "10.0", "99999999999999999999999"};+ "abc", "1O", "50pct", " 50", "50 ", "", "5e1", "50.0", "99999999999999999999999"};for (size_t i = 0; i < sizeof(unreadable) / sizeof(unreadable[0]); i++) {cbm_setenv("CBM_GATE_MAX_PARTIAL_PCT", unreadable[i], 1);int status = cli_index_grade(twenty_percent, CBM_CLI_EXIT_OK);