Deutsch   English   Français   Italiano  
<20240311104527.444@kylheku.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <433-929-6894@kylheku.com>
Newsgroups: comp.lang.c
Subject: Re: avoiding strdup()
Date: Mon, 11 Mar 2024 17:52:44 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <20240311104527.444@kylheku.com>
References: <us0brl$246bf$1@dont-email.me>
 <pan$4fc39$61bdfbef$3ca9a71a$af842694@invalid.invalid>
 <87y1ayj6hs.fsf_-_@bsb.me.uk>
 <pan$e9f7e$d6f7a386$31c353e8$a08c13cf@invalid.invalid>
 <usc845$10v6e$1@dont-email.me>
 <pan$89aca$33d2df8c$9e2c232f$d767db40@invalid.invalid>
 <ushea7$28prq$2@dont-email.me> <ushnkb$1rnlb$4@dont-email.me>
 <87r0gizzuo.fsf@nosuchdomain.example.com>
 <20240310101101.00001fd4@yahoo.com> <20240310100715.866@kylheku.com>
 <ifnHN.386274$vFZa.250421@fx13.iad> <usnb64$3n297$1@dont-email.me>
 <yMGHN.481214$PuZ9.381006@fx11.iad>
Injection-Date: Mon, 11 Mar 2024 17:52:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2dfcac18fd004bfc05446b2cad7a6cb1";
	logging-data="3941503"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+J9Tr6UQb6/VJ5qENJ0Y7bqVWtOOWW61M="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:QBOQcpeUJaK5O1hyoWH7nc6aC/E=
Bytes: 2492

On 2024-03-11, Scott Lurndal <scott@slp53.sl.home> wrote:
> Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
>>On 10/03/2024 18:47, Scott Lurndal wrote:
>>> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>>>> Not take up space in every application for a common library routine.
>>> 
>>> It's a form of lazy programming.  I've seen a lot of open source
>>> code that uses strdup without checking for failure and frequently
>>> "forgetting" to free the result.
>>
>>And it is probably more likely that machine with many gigabytes of RAM 
>
> Actually, your assumptions that:
>   1) strdup is the only allocation function used by an application
>   2) all strings are "short"

Even if a string is long enough to need its own mmap request,
that will still return valid memory that later fails to commit.

Under overcommit conditions, you will only reliably get null return out
of a large strdup if you've exhausted your local address space
(of which you have lots under 64 bits).

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca