Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connectionsPath: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Malcolm McLean
Newsgroups: comp.lang.c
Subject: Re: avoiding strdup()
Date: Tue, 12 Mar 2024 22:44:45 +0000
Organization: A noiseless patient Spider
Lines: 65
Message-ID:
References:
<87r0gizzuo.fsf@nosuchdomain.example.com> <20240310101101.00001fd4@yahoo.com>
<20240310100715.866@kylheku.com>
<87sf0w8cux.fsf@nosuchdomain.example.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 12 Mar 2024 22:44:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ed016f3d6de4e923139e945dbcc26ebc";
logging-data="584543"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+IHH2EbfukS/IT0N+NPXRI6QqO6voCOiw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Xwnl4RyfhqCb0j8qETPXDUHnx+Q=
Content-Language: en-GB
In-Reply-To:
Bytes: 4383
On 12/03/2024 15:55, Scott Lurndal wrote:
> Keith Thompson writes:
>> Malcolm McLean writes:
>>> On 11/03/2024 17:00, Scott Lurndal wrote:
>>>> Malcolm McLean writes:
>>>>> On 10/03/2024 18:47, Scott Lurndal wrote:
>>>>>> Kaz Kylheku <433-929-6894@kylheku.com> writes:
>>>>>>> On 2024-03-10, Michael S wrote:
>>>>>>>> On Sat, 09 Mar 2024 16:37:19 -0800
>>>>>>>> Keith Thompson wrote:
>>>>>>>>> strdup() and strndup() are being added to the C23 standard.
>>>>>>>>>
>>>>>>>>
>>>>>>>> What is justification?
>>>>>>>
>>>>>>> strdup is required by POSIX already and thus widely implemented.
>>>>>>> Many programmers who are not into standards already assume it's in C.
>>>>>>>
>>>>>>> For decades, portable programs have been doing things like this:
>>>>>>>
>>>>>>> #if HAVE_STRDUP
>>>>>>> #define xstrdup(s) strdup(s)
>>>>>>> #else
>>>>>>> char *xstrdup(const char *); // own definition
>>>>>>> #endif
>>>>>>>
>>>>>>>> What strdup() can do better, for any chosen value of better, than
>>>>>>>> strlen()+malloc()+memcpy() ?
>>>>>>>
>>>>>>> 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"
>>>> are both flawed.
>>>>
>>> The bank has many billions. But there is a banking crisis on and it is
>>> about to fail. And someone, somewhere, will be that man who tries to
>>> withdraw some money and is told "no". But how likely is that man to be
>>> you with your 20 pounds at the cashpoint? How likely is it to be
>>> another bank making a cash call for a 100 million or so?
>>
>> If I withdraw 20 pounds from my bank, I'll bet you that 20 pounds that
>> the bank still checks whether it has the money.
>
> And as for "how likely it is that the bank will not be able
> to honor withdrawal requests", I refer Malcolm to 1931.
>
> "In 1930, 1,352 banks held more than $853 million in
> deposits; in 1931, one year later, 2,294 banks failed
> with nearly $1.7 billion in deposits."
>
So 2,294 Americans in 1932 had the experience "you want to withdraw
cash? OK, here we go, oh sorry, that just took us over the edge and the
bank is now closed". Everyone else, either "here's your money", or
"sorry, the bank has now closed, no more withdrawal requests".
--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm