Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined behavior in qsort comparison functions for rv_histogram #526

Merged
merged 1 commit into from
Dec 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions tools/rv_histogram.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,26 @@ static rv_hist_t rv_reg_stats[] = {

static int cmp_dec(const void *a, const void *b)
{
return ((rv_hist_t *) b)->freq - ((rv_hist_t *) a)->freq;
const size_t a_freq = ((rv_hist_t *) a)->freq;
const size_t b_freq = ((rv_hist_t *) b)->freq;

if (a_freq > b_freq)
return -1;
if (a_freq < b_freq)
return 1;
return 0;
}

static int cmp_asc(const void *a, const void *b)
{
return ((rv_hist_t *) a)->freq - ((rv_hist_t *) b)->freq;
const size_t a_freq = ((rv_hist_t *) a)->freq;
const size_t b_freq = ((rv_hist_t *) b)->freq;

if (a_freq < b_freq)
return -1;
if (a_freq > b_freq)
return 1;
return 0;
}

/* used to adjust the length of histogram bar */
Expand Down
Loading