Skip to contentSkip to conversation

libtracefs: Fix add_sort_key()

PATCH New Yordan Karadzhov (VMware) 1 participant 1 message Sep 23, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libtracefs: Fix add_sort_key()

The histogram can have no 'values'. A check is required in order to prevent segfault.

Fixes 5d1c2ea(libtracefs: Implement API to create / modify and display histograms)
---
 src/tracefs-hist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/tracefs-hist.c +1 -1
index eeb8374..c112b68 100644
@@ -364,7 +364,7 @@ add_sort_key(struct tracefs_hist *hist, const char *sort_key, char **list)
 			break;
 	}
 
-	if (!key_list[i]) {
+	if (!key_list[i] && val_list) {
 		for (i = 0; val_list[i]; i++) {
 			if (strcmp(val_list[i], sort_key) == 0)
 				break;
Signature · 1 line
2.30.2