public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: Jeff Law <jeffreyalaw@gmail.com>, gcc-patches@gcc.gnu.org
Subject: Re: [PATCHv2 2/2] libiberty/buildargv: handle input consisting of only white space
Date: Fri, 28 Jun 2024 15:57:54 +0100	[thread overview]
Message-ID: <871q4h868d.fsf@redhat.com> (raw)
In-Reply-To: <87wmmvahlo.fsf@redhat.com>


Hi,

Am I OK to push these patches given the testing went OK?  I'm thinking
probably, but I don't want to overstep.

Thanks,
Andrew


Andrew Burgess <aburgess@redhat.com> writes:

> Jeff Law <jeffreyalaw@gmail.com> writes:
>
>> On 2/10/24 10:26 AM, Andrew Burgess wrote:
>>> GDB makes use of the libiberty function buildargv for splitting the
>>> inferior (program being debugged) argument string in the case where
>>> the inferior is not being started under a shell.
>>> 
>>> I have recently been working to improve this area of GDB, and noticed
>>> some unexpected behaviour to the libiberty function buildargv, when
>>> the input is a string consisting only of white space.
>>> 
>>> What I observe is that if the input to buildargv is a string
>>> containing only white space, then buildargv will return an argv list
>>> containing a single empty argument, e.g.:
>>> 
>>>    char **argv = buildargv (" ");
>>>    assert (*argv[0] == '\0');
>>>    assert (argv[1] == NULL);
>>> 
>>> We get the same output from buildargv if the input is a single space,
>>> or multiple spaces.  Other white space characters give the same
>>> results.
>>> 
>>> This doesn't seem right to me, and in fact, there appears to be a work
>>> around for this issue in expandargv where we have this code:
>>> 
>>>    /* If the file is empty or contains only whitespace, buildargv would
>>>       return a single empty argument.  In this context we want no arguments,
>>>       instead.  */
>>>    if (only_whitespace (buffer))
>>>      {
>>>        file_argv = (char **) xmalloc (sizeof (char *));
>>>        file_argv[0] = NULL;
>>>      }
>>>    else
>>>      /* Parse the string.  */
>>>      file_argv = buildargv (buffer);
>>> 
>>> I think that the correct behaviour in this situation is to return an
>>> empty argv array, e.g.:
>>> 
>>>    char **argv = buildargv (" ");
>>>    assert (argv[0] == NULL);
>>> 
>>> And it turns out that this is a trivial change to buildargv.  The diff
>>> does look big, but this is because I've re-indented a block.  Check
>>> with 'git diff -b' to see the minimal changes.  I've also removed the
>>> work around from expandargv.
>>> 
>>> When testing this sort of thing I normally write the tests first, and
>>> then fix the code.  In this case test-expandargv.c has sort-of been
>>> used as a mechanism for testing the buildargv function (expandargv
>>> does call buildargv most of the time), however, for this particular
>>> issue the work around in expandargv (mentioned above) masked the
>>> buildargv bug.
>>> 
>>> I did consider adding a new test-buildargv.c file, however, this would
>>> have basically been a copy & paste of test-expandargv.c (with some
>>> minor changes to call buildargv).  This would be fine now, but feels
>>> like we would eventually end up with one file not being updated as
>>> much as the other, and so test coverage would suffer.
>>> 
>>> Instead, I have added some explicit buildargv testing to the
>>> test-expandargv.c file, this reuses the test input that is already
>>> defined for expandargv.
>>> 
>>> Of course, once I removed the work around from expandargv then we now
>>> do always call buildargv from expandargv, and so the bug I'm fixing
>>> would impact both expandargv and buildargv, so maybe the new testing
>>> is redundant?  I tend to think more testing is always better, so I've
>>> left it in for now.
>> So just an FYI.  Sometimes folks include the -b diffs as well for these 
>> scenarios.  THe problem with doing so (as I recently stumbled over 
>> myself) is the bots which monitor the list and apply patches get quite 
>> confused by that practice.  Anyway, just something to be aware of.
>>
>> As for testing, I tend to agree, more is better unless we're highly 
>> confident its redundant.  So I'll go with your judgment on 
>> redundant-ness of the test.
>>
>> As with the prior patch, you'll need to run it through the usual 
>> bootstrap/regression cycle and cobble together a ChangeLog.
>>
>> OK once those things are taken care of.
>
> Jeff,
>
> Thanks for looking these patches over.
>
> For testing, using current(ish) gcc HEAD, on x86-64 GNU/Linux, I:
>
>   ../src/configure --prefix=$(cd .. && pwd)/install
>   make
>   make check
>
> I did this with / without my patch and then:
>
>   find . -name "*.sum"
>   ... compare all .sum files ...
>
> There was no change in any of the .sum files.
>
>   1. Am I correct that this will have run the bootstrap test by default?
>
>   2. Is there any other testing I should be doing?
>
>   3. If not, am I OK to apply both patches in this series?
>
> Thanks,
> Andrew


  reply	other threads:[~2024-06-28 14:57 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-06 16:50 [PATCH] libiberty/buildargv: POSIX behaviour for backslash handling Andrew Burgess
2024-01-02 11:22 ` Ping: " Andrew Burgess
2024-02-10 17:25 ` [PATCHv2 0/2] Changes to libiberty buildargv Andrew Burgess
2024-02-10 17:26   ` [PATCHv2 1/2] libiberty/buildargv: POSIX behaviour for backslash handling Andrew Burgess
2024-05-26 15:03     ` Jeff Law
2024-02-10 17:26   ` [PATCHv2 2/2] libiberty/buildargv: handle input consisting of only white space Andrew Burgess
2024-05-26 15:08     ` Jeff Law
2024-06-11 10:39       ` Andrew Burgess
2024-06-28 14:57         ` Andrew Burgess [this message]
2024-07-08 21:39         ` Jeff Law
2024-07-16 12:53           ` Andrew Burgess
2024-06-11 10:41       ` Andrew Burgess
2024-07-29 10:48     ` Thomas Schwinge
2024-07-29 12:51       ` Andrew Burgess
2024-07-30 20:23         ` Jeff Law
2024-08-05 11:36           ` Andrew Burgess
2024-04-27  9:48   ` [PATCHv2 0/2] Changes to libiberty buildargv Andrew Burgess

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=871q4h868d.fsf@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jeffreyalaw@gmail.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).