XPost: alt.folklore.computers, alt.unix.geeks
From: bowman@montana.com
On Tue, 06 Jan 2026 22:54:26 +0000, Richard Kettlewell wrote:
> scott@slp53.sl.home (Scott Lurndal) writes:
>> rbowman writes:
>>>On Tue, 06 Jan 2026 18:57:04 GMT, Charlie Gibbs wrote:
>>>> Inspired by readline(), I've written my own replacements for strcpy()
>>>> and strcat() that do much the same thing.
>>>
>>>To quote from the strcat man page "Read about Shlemiel the painter.".
>>>stpcpy() was a late arrival and I never used it. I do use a similar
>>>construct
>>>
>>>char buf[1024];
>>>char* ptr = buf;
>>>
>>>ptr += sprintf(ptr, "%s", "some stuff");
>>>ptr += sprintf(ptr, "%s", " some more stuff");
>>
>> I would suggest using snprintf instead of sprintf to prevent accesses
>> beyond (buf + 1024). A bit more complicated if you want to know that
>> the result was truncated, since you need to adjust the remaining length
>> based on the return value from the prior snprintf, as well as checking
>> for overflow.
>
> This is calling out for a wrapping up in a function or two that can do
> the book-keeping automatically (and use an expandable buffer, if the use
> case demands).
Ah, mission creep...
--- SoupGate-Win32 v1.05
* Origin: you cannot sedate... all the things you hate (1:229/2)
|