Skip to contentSkip to conversation

kernel-shark: Fixing the fix in ksmodel_zoom

PATCH New Yordan Karadzhov 1 participant 1 message Apr 22, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kernel-shark: Fixing the fix in ksmodel_zoom

if (zoom_in && (int) range * (1. - r) < histo->n_bins * 5)

The line above has two bugs:
- 64 bit type (size_t) is casted to 32 bit (int)
- Type cast operator has a higher precedence than the multiplication operator, hence "(int) range * (1. - r)" is a floating point number

Fixes bedcff1165 ("kernel-shark: Fix a bug in ksmodel_zoom")
---
 kernel-shark/src/libkshark-model.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel-shark/src/libkshark-model.c +1 -1
index 29676c7..978cd70 100644
@@ -649,7 +649,7 @@ static void ksmodel_zoom(struct kshark_trace_histo *histo,
 	 * Avoid overzooming. If needed, adjust the Scale factor to a the value
 	 * which provides bin_size >= 5.
 	 */
-	if (zoom_in && (int) range * (1. - r) < histo->n_bins * 5)
+	if (zoom_in && (size_t) (range * (1. - r)) < histo->n_bins * 5)
 		r = 1. - (histo->n_bins * 5.) / range;
 
 	/*
Signature · 1 line
2.20.1