Deutsch English Français Italiano |
<875xxsa7gk.fsf@nosuchdomain.example.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!feeds.phibee-telecom.net!2.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson <Keith.S.Thompson+u@gmail.com> Newsgroups: comp.lang.c Subject: Re: avoiding strdup() Date: Mon, 11 Mar 2024 12:34:19 -0700 Organization: None to speak of Lines: 33 Message-ID: <875xxsa7gk.fsf@nosuchdomain.example.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> <20240311104527.444@kylheku.com> <wwv7ci837oa.fsf@LkoBDZeT.terraraq.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: dont-email.me; posting-host="803e1d91970c7135fb6b17cffb70db2d"; logging-data="3990758"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gEWXayEIu94bX63j/vF99" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) Cancel-Lock: sha1:HcmiD9PG0aL9VV/fjiHWlFsmFyI= sha1:lq1Mxjc/OpjQychjc0kuA4/1Ugw= Bytes: 3054 Richard Kettlewell <invalid@invalid.invalid> writes: > Kaz Kylheku <433-929-6894@kylheku.com> writes: >> 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. > > Since strdup necessarily writes to almost all the memory it allocates, > you’d expect the failure to be immediate. Yes, but that write happens *after* the malloc() call, so it won't necessarily be reflected in the value returned by strdup(). It could crash the current program, or in the worst case it could cause the OoM killer to kill some other process. -- Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com Working, but not speaking, for Medtronic void Void(void) { Void(); } /* The recursive call of the void */