public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Joern Rennecke <amylaar@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-825] Avoid outputting corrupt string constructor when host/target chars mismatch. Date: Mon, 17 May 2021 10:23:42 +0000 (GMT) [thread overview] Message-ID: <20210517102342.2F1B63838026@sourceware.org> (raw) https://gcc.gnu.org/g:a8e19fa4198ea2504c89d01741d11766e0e9e91b commit r12-825-ga8e19fa4198ea2504c89d01741d11766e0e9e91b Author: Joern Rennecke <joern.rennecke@embecosm.com> Date: Mon May 17 10:57:23 2021 +0100 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: --- gcc/c-family/c-common.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 7bd799d1825..b7daa2e2654 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
reply other threads:[~2021-05-17 10:23 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210517102342.2F1B63838026@sourceware.org \ --to=amylaar@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).