From: Jan Beulich <jbeulich@suse.com>
To: binutils@emagii.com
Cc: nickc@redhat.com, Ulf Samuelsson <ulf@emagii.com>,
binutils@sourceware.org
Subject: Re: [PATCH v1 3/7] ldlang.*: process ASCII command
Date: Mon, 1 Jul 2024 08:35:07 +0200 [thread overview]
Message-ID: <5bdf0229-4de0-4cba-8dc3-34380f7abf7a@suse.com> (raw)
In-Reply-To: <20240628214627.6726-4-binutils@emagii.com>
On 28.06.2024 23:46, binutils@emagii.com wrote:
> --- a/ld/ldlang.c
> +++ b/ld/ldlang.c
> @@ -8663,15 +8663,20 @@ lang_add_data (int type, union etree_union *exp)
> new_stmt->type = type;
> }
>
> -void
> -lang_add_string (const char *s)
> +/* Convert escape codes in S.
> + Supports \n, \r, \t and \NNN octals.
> + Returns a copy of S in a malloc'ed buffer. */
> +
> +static char *
> +convert_string (const char * s)
> {
> - bfd_vma len = strlen (s);
> - bfd_vma i;
> - bool escape = false;
> + size_t len = strlen (s);
> + size_t i;
> + bool escape = false;
> + char * buffer = malloc (len + 1);
You want to avoid crashing if this allocation fails. Perhaps by simply
using xmalloc() or e.g. XNEWVEC().
> + char * b;
>
> - /* Add byte expressions until end of string. */
> - for (i = 0 ; i < len; i++)
> + for (i = 0, b = buffer; i < len; i++)
> {
> char c = *s++;
>
> @@ -8729,21 +8734,53 @@ lang_add_string (const char *s)
> }
> break;
> }
> -
> - lang_add_data (BYTE, exp_intop (c));
> escape = false;
> }
> else
> {
> if (c == '\\')
> - escape = true;
> - else
> - lang_add_data (BYTE, exp_intop (c));
> + {
> + escape = true;
> + continue;
> + }
> }
> +
> + * b ++ = c;
> }
>
> - /* Remeber to terminate the string. */
> - lang_add_data (BYTE, exp_intop (0));
> + * b = 0;
> + return buffer;
> +}
> +
> +void
> +lang_add_string (size_t size, const char *s)
> +{
> + size_t len;
> + size_t i;
> + char * string;
> +
> + string = convert_string (s);
> + len = strlen (string);
> +
> + /* Check if it is ASCIZ command (len == 0) */
> + if (size == 0)
> + /* Make sure that we include the terminating nul byte. */
> + size = len + 1;
> + else if (len >= size)
> + {
> + len = size - 1;
> +
> + einfo (_("%P:%pS: warning: ASCII string does not fit in allocated space,"
> + " truncated\n"), NULL);
> + }
> +
> + for (i = 0 ; i < len ; i++)
Nit: No blanks before ; please.
Jan
next prev parent reply other threads:[~2024-07-01 6:35 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-28 21:46 [PATCH v1 0/7] ASCII output section command binutils
2024-06-28 21:46 ` [PATCH v1 1/7] ldlex.l: Add ASCII token binutils
2024-06-28 21:46 ` [PATCH v1 2/7] ldgram.y: Add ASCII parsing binutils
2024-06-28 21:46 ` [PATCH v1 3/7] ldlang.*: process ASCII command binutils
2024-07-01 6:35 ` Jan Beulich [this message]
2024-06-28 21:46 ` [PATCH v1 4/7] ld.texi: Add ASCII to info file binutils
2024-07-01 6:50 ` Jan Beulich
[not found] ` <6FDD8EBD-2371-40DB-B25B-052278BCBF49@emagii.com>
2024-07-02 8:12 ` Jan Beulich
2024-07-05 15:38 ` Ulf Samuelsson
2024-07-08 6:18 ` Jan Beulich
2024-07-08 10:57 ` Ulf Samuelsson
2024-07-08 11:07 ` Jan Beulich
2024-07-08 11:19 ` Ulf Samuelsson
2024-07-08 11:18 ` Andreas Schwab
2024-07-08 11:29 ` Ulf Samuelsson
2024-07-08 11:40 ` Jan Beulich
2024-07-08 12:10 ` Ulf Samuelsson
2024-07-08 11:48 ` Andreas Schwab
2024-07-08 12:01 ` Ulf Samuelsson
2024-07-08 12:16 ` Andreas Schwab
2024-07-08 12:22 ` Ulf Samuelsson
2024-06-28 21:46 ` [PATCH v1 5/7] Add testsuite for ASCII command binutils
2024-06-28 21:46 ` [PATCH v1 6/7] NEWS: Add " binutils
2024-06-28 21:46 ` [PATCH v1 7/7] ChangeLog: " binutils
2024-07-01 6:38 ` Jan Beulich
[not found] ` <094CF629-FDF8-436D-8B5B-62D35C3EA396@emagii.com>
2024-07-02 8:37 ` Jan Beulich
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=5bdf0229-4de0-4cba-8dc3-34380f7abf7a@suse.com \
--to=jbeulich@suse.com \
--cc=binutils@emagii.com \
--cc=binutils@sourceware.org \
--cc=nickc@redhat.com \
--cc=ulf@emagii.com \
/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: link
Be 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).