Skip to contentSkip to conversation

libtraceeval: Fix traceeval_insert() macro for NULL vals

PATCH In review Steven Rostedt 2 participants 2 messages Sep 29, 2023 – Oct 2, 2023

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libtraceeval: Fix traceeval_insert() macro for NULL vals

From: "Steven Rostedt (Google)" <[email protected]>

If the vals is NULL (which is valid), the traceeval_insert() macro calls traceeval_insert_size() with sizeof(vals)/sizeof(vals[0]) to get the number of vals in the array. But this does not make sense with a NULL value. Check for NULL and if vals is NULL then pass in zero.

---
Changse since v1: https://lore.kernel.org/linux-trace-devel/[email protected]

- typecast "vals" to (void *) otherwise the compiler will warn that comparing a structure to != NULL will always be true.

 include/traceeval-hist.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/traceeval-hist.h +1 -1
index 44d071f3231a..65a905034773 100644
@@ -187,7 +187,7 @@ int traceeval_insert_size(struct traceeval *teval,
 
 #define traceeval_insert(teval, keys, vals)				\
 	traceeval_insert_size(teval, keys, TRACEEVAL_ARRAY_SIZE(keys), \
-			      vals, TRACEEVAL_ARRAY_SIZE(vals))
+			      vals, (void *)vals == NULL ? 0 : TRACEEVAL_ARRAY_SIZE(vals))
 
 int traceeval_remove_size(struct traceeval *teval,
 			  const struct traceeval_data *keys, size_t nr_keys);
Signature · 1 line
2.40.1
Reviewed-by on v2 1/1
#1 lore raw
Quoted 10 lines · Steven Rostedt

From: "Steven Rostedt (Google)" <[email protected]>

If the vals is NULL (which is valid), the traceeval_insert() macro calls traceeval_insert_size() with sizeof(vals)/sizeof(vals[0]) to get the number of vals in the array. But this does not make sense with a NULL value. Check for NULL and if vals is NULL then pass in zero.