From 59d419cf1252982a2e0277601280279245ffd22e Mon Sep 17 00:00:00 2001 From: Adhemerval Zanella Date: Thu, 17 Apr 2025 18:03:16 -0300 Subject: [PATCH] locate: Fix UB on memcpy call The ubsan triggers: UBSAN: Undefined behaviour in programs/charmap.c:908:2 null pointer passed as argument 2, nonnull attribute declared at unknown:0:0 This is not an isseu since size is always '0' in this case. --- locale/programs/charmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/locale/programs/charmap.c b/locale/programs/charmap.c index 58433c8c5b..07d406e12f 100644 --- a/locale/programs/charmap.c +++ b/locale/programs/charmap.c @@ -904,9 +904,9 @@ number of bytes for byte sequence of beginning and end of range not the same: %d (struct width_rule *) obstack_alloc (&result->mem_pool, (new_size * sizeof (struct width_rule))); - - memcpy (new_rules, result->width_rules, - result->nwidth_rules_max * sizeof (struct width_rule)); + if (result->width_rules != NULL) + memcpy (new_rules, result->width_rules, + result->nwidth_rules_max * sizeof (struct width_rule)); result->width_rules = new_rules; result->nwidth_rules_max = new_size; -- 2.47.2