From 26ada583a06dc06a042bd355af983f37e431d8b6 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 5 Feb 2019 22:08:15 -0800 Subject: [PATCH] Fix te_expr's flexible array member te_expr has a flexible array member, but it's declared as size 1. Stop declaring its size so UBSan stops complaining. Noted in #2852 --- src/tinyexpr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tinyexpr.cpp b/src/tinyexpr.cpp index 6cfba346d..842219dea 100644 --- a/src/tinyexpr.cpp +++ b/src/tinyexpr.cpp @@ -56,7 +56,7 @@ int get_arity(const int type) { typedef struct te_expr { int type; union {double value; const void *function;}; - te_expr *parameters[1]; + te_expr *parameters[]; } te_expr; // TODO: Rename since variables have been removed. @@ -92,7 +92,7 @@ void te_free(te_expr *n); static te_expr *new_expr(const int type, const te_expr *parameters[]) { const int arity = get_arity(type); const int psize = sizeof(te_expr*) * arity; - const int size = (sizeof(te_expr) - sizeof(void*)) + psize; + const int size = sizeof(te_expr) + psize; te_expr *ret = (te_expr *)malloc(size); // This sets float to 0, which depends on the implementation. // We rely on IEEE-754 floats anyway, so it's okay.