Re: [PATCH 1/2] gpg-interface: handle missing " with " gracefully in parse_ssh_output()
- From
René Scharfe <l.s.r@web.de>
- Date
- Nov 1, 2021, 18:36 UTC
- Message-ID
- <abc4c174-f848-a0f4-3f1d-486ee8f275b2@web.de>
- In-Reply-To
- <dedf3971-adb1-c355-0b05-4e94ad92e1f7@gigacodes.de>
Am 01.11.21 um 09:40 schrieb Fabian Stelzer:
Show 8 quoted lines
> On 30.10.21 19:04, René Scharfe wrote:
>> Silly bonus question: What's the purpose of the "+ 1" and "- 1", which
>> seem to cancel each other out?
>
> They do. But only for the xmemdupz. It is important for the strstr() to
> skip over already found strings (" with " could be in the principal name
> as well - multiple times even). And doing strstr(line +1, ...) can be
> problematic for the first iteration.Ah, right.
Show 5 quoted lines
>> do {
>> search = strstr(line, " with ");
>> if (search)
>> line = search + 1;
>> } while (search != NULL);This can be shortened to:
while ((search = strstr(line, " with "))) line = search + 1;
I still would have tripped over the +1 / -1, though. Calling an rfind() or strrstr() or find_last() function that deals with it internally would have helped me avoid that, I think, but we don't have use for such a thing anywhere else.
René