Skip to content

Commit fad2a51

Browse files
committed
fix(search): treat metadata encoding failure as an error in tree output
json_result() owns and disposes the serialized metadata that ranked_tree() and the tree branch of cbm_search_operation_execute() turn into tree text. When allocation or encoding fails, it returns an error payload with is_error=true. Both callers checked only the payload, so they could render that error text as metadata and never take their encoding-failure path. Both callers now require !is_error && payload before calling cbm_json_to_tree(). Disposal and the existing failure paths are unchanged. The integration worker found this while merging fu/toon-output and fu/argparse-memcore, and proposed the fix.
1 parent fdc8e28 commit fad2a51

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

‎src/operations/search.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ static char *ranked_tree(const char *json) {
252252
yyjson_mut_obj_remove_key(metadata_root, "rows");
253253
yyjson_mut_obj_remove_key(metadata_root, "cols");
254254
cbm_operation_result_t metadata_result = json_result(metadata_doc, false);
255-
char *metadata = metadata_result.payload ? cbm_json_to_tree(metadata_result.payload) : NULL;
255+
char *metadata = !metadata_result.is_error && metadata_result.payload
256+
? cbm_json_to_tree(metadata_result.payload)
257+
: NULL;
256258
cbm_operation_result_dispose(&metadata_result);
257259
if (!metadata) {
258260
cbm_sb_free(&sb);
@@ -1097,8 +1099,9 @@ cbm_operation_result_t cbm_search_operation_execute(const char *args) {
10971099
}
10981100
}
10991101
cbm_operation_result_t metadata_result = json_result(doc, false);
1100-
char *metadata =
1101-
metadata_result.payload ? cbm_json_to_tree(metadata_result.payload) : NULL;
1102+
char *metadata = !metadata_result.is_error && metadata_result.payload
1103+
? cbm_json_to_tree(metadata_result.payload)
1104+
: NULL;
11021105
cbm_operation_result_dispose(&metadata_result);
11031106
cbm_sb_t tree;
11041107
cbm_sb_init(&tree);

0 commit comments

Comments
 (0)