From patchwork Fri Sep 29 09:13:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steven Rostedt X-Patchwork-Id: 13403944 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 57AD611711 for ; Fri, 29 Sep 2023 09:13:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0125C433C7; Fri, 29 Sep 2023 09:13:09 +0000 (UTC) Date: Fri, 29 Sep 2023 05:13:04 -0400 From: Steven Rostedt To: Linux Trace Devel Cc: Ross Zwisler , Stevie Alvarez Subject: [PATCH v2] libtraceeval: Fix traceeval_insert() macro for NULL vals Message-ID: <20230929051304.7b157905@rorschach.local.home> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-trace-devel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: "Steven Rostedt (Google)" 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 Cc: Stevie Alvarez Signed-off-by: Steven Rostedt (Google) Reviewed-by: Ross Zwisler --- 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(-) 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);