Skip to content

Commit 60449f8

Browse files
committed
style(mcp): pick the unreadable-count hint with an if/else chain
cppcheck 2.20 flags the nested ternary in handle_index_status: src/mcp/mcp.c:6705:30: style: Condition 'nodes<0' is always false [knownConditionTrueFalse] After the `nodes < 0 && edges < 0` arm, cppcheck's value flow takes `nodes < 0` to be the false half of that conjunction and rejects the second test. Select the hint with a plain if / else-if / else chain into a `const char *hint` and add it once, rather than suppressing the check. The three messages are byte-identical to before — only the line wrapping of the adjacent literals moved — so status, counts and hint text are unchanged and the tests added in the previous commit still describe the behaviour. Verified with cppcheck 2.21 locally using the flags from Makefile.cbm's lint-cppcheck target: the finding is reproduced on the parent commit and gone here, with no new ones. clang-format reports no drift over the changed lines. Signed-off-by: kavish-19 <[email protected]>
1 parent 73c509f commit 60449f8

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

‎src/mcp/mcp.c‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6696,18 +6696,19 @@ static char *handle_index_status(cbm_mcp_server_t *srv, const char *args) {
66966696
safe_str_free(&proj_info.indexed_at);
66976697
safe_str_free(&proj_info.root_path);
66986698
if (counts_unreadable) {
6699-
yyjson_mut_obj_add_str(
6700-
doc, root, "hint",
6701-
nodes < 0 && edges < 0
6702-
? "The nodes and edges tables could not be read; the database may be "
6703-
"corrupt. Re-run index_repository(repo_path=...) or remove the project "
6704-
"cache and re-index."
6705-
: (nodes < 0 ? "The nodes table could not be read; the database may be "
6706-
"corrupt. Re-run index_repository(repo_path=...) or remove "
6707-
"the project cache and re-index."
6708-
: "The edges table could not be read; the database may be "
6709-
"corrupt. Re-run index_repository(repo_path=...) or remove "
6710-
"the project cache and re-index."));
6699+
const char *hint;
6700+
if (nodes < 0 && edges < 0) {
6701+
hint = "The nodes and edges tables could not be read; the database may be "
6702+
"corrupt. Re-run index_repository(repo_path=...) or remove the project "
6703+
"cache and re-index.";
6704+
} else if (nodes < 0) {
6705+
hint = "The nodes table could not be read; the database may be corrupt. Re-run "
6706+
"index_repository(repo_path=...) or remove the project cache and re-index.";
6707+
} else {
6708+
hint = "The edges table could not be read; the database may be corrupt. Re-run "
6709+
"index_repository(repo_path=...) or remove the project cache and re-index.";
6710+
}
6711+
yyjson_mut_obj_add_str(doc, root, "hint", hint);
67116712
} else if (nodes == 0) {
67126713
yyjson_mut_obj_add_str(
67136714
doc, root, "hint",

0 commit comments

Comments
 (0)