Skip to content

Commit

Permalink
Sort search hits before emitting returning them. (#4925)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rot127 authored Feb 23, 2025
1 parent efbab1d commit 89dcfe2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions librz/search/search.c
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,27 @@ RZ_API RZ_OWN RzList /*<RzSearchHit *>*/ *rz_search_on_io(
rz_th_lock_free(ctx.io_lock);
rz_list_free(windows);
rz_th_queue_free(hits);

rz_list_sort(results, (RzListComparator)rz_search_hit_cmp, NULL);
return results;
}

RZ_IPI int rz_search_hit_cmp(RZ_NULLABLE RzSearchHit *a, RZ_NULLABLE RzSearchHit *b, void *user) {
if (!a && !b) {
return 0;
} else if (!a) {
return -1;
} else if (!b) {
return 1;
}
if (a->address == b->address) {
return 0;
} else if (a->address < b->address) {
return -1;
}
return 1;
}

/**
* \brief Allocate and initialize a new RzSearchHit
*
Expand Down
1 change: 1 addition & 0 deletions librz/search/search_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ struct rz_search_find_opt_t {

RZ_IPI RZ_OWN RzSearchHit *rz_search_hit_new(const char *metadata, ut64 address, size_t size);
RZ_IPI void rz_search_hit_free(RZ_NULLABLE RzSearchHit *hit);
RZ_IPI int rz_search_hit_cmp(RZ_NULLABLE RzSearchHit *a, RZ_NULLABLE RzSearchHit *b, void *user);

RZ_IPI RZ_OWN RzSearchCollection *rz_search_collection_new_bytes_space(RZ_NONNULL RzSearchFindBytesCallback find, RZ_NONNULL RzSearchIsEmptyCallback is_empty, RZ_NULLABLE RzSearchFreeCallback free, RZ_NULLABLE void *user);
RZ_IPI RZ_OWN RzSearchCollection *rz_search_collection_new_graph_space(RZ_NONNULL RzSearchFindGraphCallback find, RZ_NONNULL RzSearchIsEmptyCallback is_empty, RZ_NULLABLE RzSearchFreeCallback free, RZ_NULLABLE void *user);
Expand Down

0 comments on commit 89dcfe2

Please sign in to comment.