Skip to content

Commit

Permalink
Fix integer truncation on abs() call
Browse files Browse the repository at this point in the history
GCC 10 complains about possible integer truncation when passing a long
int to abs().

Signed-off-by: Nathaniel Graff <nathaniel.graff@sifive.com>
  • Loading branch information
nategraff-sifive committed Aug 25, 2020
1 parent 8dc0978 commit 771ad8d
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/drivers/sifive_fe310-g000_pll.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,13 @@ static int find_closest_config(long ref_hz, long rate) {
i--) {
long config_freq = get_pll_config_freq(ref_hz, &(pll_configs[i]));
if (config_freq != PLL_CONFIG_NOT_VALID) {
long freq_diff = abs(config_freq - rate);
long freq_diff;
if (config_freq > rate) {
freq_diff = config_freq - rate;
} else {
freq_diff = rate - config_freq;
}

if (freq_diff < closest_diff) {
closest_index = i;
closest_diff = freq_diff;
Expand Down

0 comments on commit 771ad8d

Please sign in to comment.