diff mbox series

[v2] libtraceeval: Fix traceeval_insert() macro for NULL vals

Message ID 20230929051304.7b157905@rorschach.local.home (mailing list archive)
State Accepted
Headers show
Series [v2] libtraceeval: Fix traceeval_insert() macro for NULL vals | expand

Commit Message

Steven Rostedt Sept. 29, 2023, 9:13 a.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

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.

Cc: Ross Zwisler <zwisler@google.com>
Cc: Stevie Alvarez <stevie.6strings@gmail.com>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
Changse since v1: https://lore.kernel.org/linux-trace-devel/20230928051511.074ab689@rorschach.local.home

 - 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(-)

Comments

Ross Zwisler Oct. 2, 2023, 8:45 p.m. UTC | #1
On Fri, Sep 29, 2023 at 05:13:04AM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> 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.
> 
> Cc: Ross Zwisler <zwisler@google.com>
> Cc: Stevie Alvarez <stevie.6strings@gmail.com>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>

Reviewed-by: Ross Zwisler <zwisler@google.com>
diff mbox series

Patch

diff --git a/include/traceeval-hist.h b/include/traceeval-hist.h
index 44d071f3231a..65a905034773 100644
--- a/include/traceeval-hist.h
+++ b/include/traceeval-hist.h
@@ -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);