Am 25.08.19 um 12:02 schrieb Mike Hommey:
> On Sun, Aug 25, 2019 at 04:10:55AM -0400, Jeff King wrote:
>> diff --git a/fast-import.c b/fast-import.c
>> index ee7258037a..1f9160b645 100644
>> --- a/fast-import.c
>> +++ b/fast-import.c
>> @@ -1763,7 +1763,6 @@ static int read_next_command(void)
>> } else {
>> struct recent_command *rc;
>>
>> - strbuf_detach(&command_buf, NULL);
>> stdin_eof = strbuf_getline_lf(&command_buf, stdin);
>> if (stdin_eof)
>> return EOF;
>> @@ -1784,7 +1783,7 @@ static int read_next_command(void)
>> free(rc->buf);
>> }
>>
>> - rc->buf = command_buf.buf;
>> + rc->buf = xstrdup(command_buf.buf);
>
> You could xstrndup(command_buf.buf, command_buf.len), which would avoid
> a hidden strlen.
xstrndup() also searches for NUL, albeit with memchr(3). xmemdupz()
would copy without checking.
I suspect the simplicity of xstrdup() outweighs the benefits of the
alternatives, but didn't do any measurements..
René