From: Joern Rennecke Date: Mon, 17 May 2021 09:57:23 +0000 (+0100) Subject: Avoid outputting corrupt string constructor when host/target chars mismatch. X-Git-Tag: upstream/12.2.0~7872 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a8e19fa4198ea2504c89d01741d11766e0e9e91b;p=platform%2Fupstream%2Fgcc.git Avoid outputting corrupt string constructor when host/target chars mismatch. * c-common.c (braced_list_to_string): Return CTOR unchanged if host and target character sizes don't match. --- diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 7bd799d..b7daa2e 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -9059,6 +9059,12 @@ braced_list_to_string (tree type, tree ctor, bool member) if (!member && !tree_fits_uhwi_p (typesize)) return ctor; + /* If the target char size differes from the host char size, we'd risk + loosing data and getting object sizes wrong by converting to + host chars. */ + if (TYPE_PRECISION (char_type_node) != CHAR_BIT) + return ctor; + /* If the array has an explicit bound, use it to constrain the size of the string. If it doesn't, be sure to create a string that's as long as implied by the index of the last zero specified via