git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] parse-options: use COPY_ARRAY in parse_options_concat()

From
René Scharfe <l.s.r@web.de>
Date
Nov 14, 2019, 16:01 UTC
Message-ID
<686d3b30-9f1e-a871-7dab-e35f1d6d1499@web.de>
In-Reply-To
<20191113182548.1707-1-martin.agren@gmail.com>
Am 13.11.19 um 19:25 schrieb Martin Ågren:
Show 17 quoted lines
> On Wed, 13 Nov 2019 at 18:19, René Scharfe <l.s.r@web.de> wrote:
>>         ALLOC_ARRAY(ret, st_add3(a_len, b_len, 1));
>> -       for (i = 0; i < a_len; i++)
>> -               ret[i] = a[i];
>> -       for (i = 0; i < b_len; i++)
>> -               ret[a_len + i] = b[i];
>> +       COPY_ARRAY(ret, a, a_len);
>> +       COPY_ARRAY(ret + a_len, b, b_len);
>>         ret[a_len + b_len] = b[b_len]; /* final OPTION_END */
>
> Maybe include that last one in the COPY_ARRAY with something like this
> on top?
>
> -       COPY_ARRAY(ret + a_len, b, b_len);
> -       ret[a_len + b_len] = b[b_len]; /* final OPTION_END */
> +       /* 1 more to include the final OPTION_END */
> +       COPY_ARRAY(ret + a_len, b, st_add(b_len, 1));

I'd rather move towards allowing a and b to be NULL, for consistency and safety. Will send patches eventually, but preferably only once the original patch hits master. These follow-ups that I have in mind aren't terribly urgent.

René
Previous: Martin Ågren
Message 5 of 5 in “parse-options: avoid arithmetic on pointer that's potentially NULL”
  1. René ScharfeNov 12, 2019
  2. Junio C HamanoNov 13, 2019
  3. René ScharfeNov 13, 2019
  4. Martin ÅgrenNov 13, 2019
  5. René ScharfeNov 14, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.