Re: avoiding strdup()

Liste des GroupesRevenir à l c 
Sujet : Re: avoiding strdup()
De : malcolm.arthur.mclean (at) *nospam* gmail.com (Malcolm McLean)
Groupes : comp.lang.c
Date : 13. Mar 2024, 11:50:28
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <usrst4$sqrc$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
User-Agent : Mozilla Thunderbird
On 12/03/2024 22:31, Keith Thompson wrote:
Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
On 12/03/2024 01:20, Keith Thompson wrote:
Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
[...]
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.  I'd rather
write correct code than code that almost certainly happens to work.
Sure, strdup() is unlikely to fail-- but I'm going to check the
result.
>
And how often do banks fail, actually, and how often does government
take action when it's heading that way, but nowhere near failing yet?
The government isn't going to intervene when your laptop is running
low on memory.
>
No, it's an analogy. You run lots of apps gobbling lots of memory, and
maybe a program won't launch or thngs start to slow or a warning comes
up, and you realise that soon the program of interest might run out of
memory, and so you shut other things down so that that doesn't happen.
And so it's pretty rare to actually run out of memory unless the
program isn't correct and there is a leak.
 Are you relying in a person sitting in front of the computer and
noticing that memory is running low?  The vast majority of software
doesn't have someone watching it.
 
The server runs out of memory once. Sometimes yes, it's "these things happen, just get it back up". But more often. it's "Can't have that happening again. Shut something else down we don;t really need, or maybe buy an extra 2GB. Only ten dollars after all."

I agree that an allocation failure in strdup() is unlikely.  Are you
suggesting that that means you needn't bother checking the result?
 
If it's genuinely the case that an electrical faiure is more likely, is there a really a point? But for my code, the test would go in, because it usually is intended to last for a very long time, and small memory machines might come back into fashion (eg smaller but very cheap and very fast, or maybe it will be used in an embedded system)
--
Check out Basic Algorithms and my other books:
https://www.lulu.com/spotlight/bgy1mm

Date Sujet#  Auteur
7 Mar 24 * Re: [OT] UTF-8 sig. Was: "White House to Developers: Using C or C++ Invites Cybersecurity Risks"51Ben
9 Mar 24 `* Re: [OT] UTF-8 sig. Was: "White House to Developers: Using C or C++ Invites Cybersecurity Risks"50Blue-Maned_Hawk
9 Mar 24  +* Re: [OT] UTF-8 sig. Was: "White House to Developers: Using C or C++ Invites Cybersecurity Risks"5Keith Thompson
9 Mar 24  i`* Re: [OT] UTF-8 sig. Was: "White House to Developers: Using C or C++ Invites Cybersecurity Risks"4Blue-Maned_Hawk
9 Mar 24  i `* Re: [OT] UTF-8 sig.3vallor
10 Mar 24  i  `* Re: [OT] UTF-8 sig.2Blue-Maned_Hawk
21 Mar 24  i   `- Re: [OT] UTF-8 sig.1Anton Shepelev
9 Mar 24  `* Re: [OT] UTF-8 sig.44Ben
9 Mar 24   +* Re: [OT] UTF-8 sig.3Richard Harnden
10 Mar 24   i`* Re: [OT] UTF-8 sig.2Ben Bacarisse
10 Mar 24   i `- Re: [OT] UTF-8 sig.1Richard Harnden
9 Mar 24   +* Re: [OT] UTF-8 sig.7Blue-Maned_Hawk
9 Mar 24   i`* Re: [OT] UTF-8 sig.6Richard Harnden
10 Mar 24   i +- Re: [OT] UTF-8 sig.1Blue-Maned_Hawk
10 Mar 24   i `* Re: [OT] UTF-8 sig.4Ben Bacarisse
10 Mar 24   i  `* Re: [OT] UTF-8 sig.3Michael S
10 Mar 24   i   +- Re: [OT] UTF-8 sig.1Blue-Maned_Hawk
10 Mar 24   i   `- Re: [OT] UTF-8 sig.1Kaz Kylheku
9 Mar 24   `* avoiding strdup() (was: Re: [OT] UTF-8 sig.)33vallor
9 Mar 24    +- Re: avoiding strdup()1Spiros Bousbouras
10 Mar 24    +* Re: avoiding strdup()30Keith Thompson
10 Mar 24    i`* Re: avoiding strdup()29Michael S
10 Mar 24    i +- Re: avoiding strdup()1Blue-Maned_Hawk
10 Mar 24    i `* Re: avoiding strdup()27Kaz Kylheku
10 Mar 24    i  +- Re: avoiding strdup()1Richard Harnden
11 Mar 24    i  +* Re: avoiding strdup()22Malcolm McLean
11 Mar 24    i  i+* Re: avoiding strdup()10Michael S
11 Mar 24    i  ii+* Re: avoiding strdup()6Keith Thompson
11 Mar 24    i  iii+* Re: avoiding strdup()2Kaz Kylheku
11 Mar 24    i  iiii`- Re: avoiding strdup()1Keith Thompson
11 Mar 24    i  iii+- Re: avoiding strdup()1Keith Thompson
11 Mar 24    i  iii`* Re: avoiding strdup()2Spiros Bousbouras
11 Mar 24    i  iii `- Re: avoiding strdup()1Keith Thompson
11 Mar 24    i  ii`* Re: avoiding strdup()3Michael S
11 Mar 24    i  ii +- Re: avoiding strdup()1Michael S
11 Mar 24    i  ii `- Re: avoiding strdup()1Spiros Bousbouras
11 Mar 24    i  i+* Re: avoiding strdup()3Kaz Kylheku
11 Mar 24    i  ii`* Re: avoiding strdup()2Richard Kettlewell
11 Mar 24    i  ii `- Re: avoiding strdup()1Keith Thompson
12 Mar 24    i  i`* Re: avoiding strdup()8Malcolm McLean
12 Mar 24    i  i `* Re: avoiding strdup()7Keith Thompson
12 Mar 24    i  i  +* Re: avoiding strdup()3Malcolm McLean
13 Mar 24    i  i  i`* Re: avoiding strdup()2Keith Thompson
13 Mar 24    i  i  i `- Re: avoiding strdup()1Malcolm McLean
13 Mar 24    i  i  `* Re: avoiding strdup()3Malcolm McLean
13 Mar 24    i  i   `* Re: avoiding strdup()2James Kuyper
13 Mar 24    i  i    `- Re: avoiding strdup()1David Brown
29 Apr 24    i  `* Re: avoiding strdup()3Lawrence D'Oliveiro
29 Apr 24    i   `* Re: avoiding strdup()2i
1 May 24    i    `- Re: avoiding strdup()1steve
10 Mar 24    `- Re: avoiding strdup()1Richard Harnden

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal