From: Martin Liska Date: Mon, 16 May 2022 07:48:27 +0000 (+0200) Subject: Fix ubsan error in opts-global.cc X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ec69db6be6912e45fa5f54f2d231d56e52612f1d;p=platform%2Fupstream%2Fgcc.git Fix ubsan error in opts-global.cc Fixes: opts-global.cc:75:15: runtime error: store to address 0x00000bc9be70 with insufficient space for an object of type 'char' which happens when mask == 0, len == 0 and we allocate zero elements. Eventually, result[0] is called which triggers the UBSAN. gcc/ChangeLog: * opts-global.cc (write_langs): Allocate at least one byte. --- diff --git a/gcc/opts-global.cc b/gcc/opts-global.cc index a18c769..4f5f8cd 100644 --- a/gcc/opts-global.cc +++ b/gcc/opts-global.cc @@ -61,7 +61,7 @@ write_langs (unsigned int mask) if (mask & (1U << n)) len += strlen (lang_name) + 1; - result = XNEWVEC (char, len); + result = XNEWVEC (char, MAX (1, len)); len = 0; for (n = 0; (lang_name = lang_names[n]) != 0; n++) if (mask & (1U << n))