Path: ...!2.eu.feeder.erje.net!feeder.erje.net!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:58:03 -0000 (UTC) Organization: A noiseless patient Spider Lines: 24 Message-ID: <20240311105508.215@kylheku.com> References: <87y1ayj6hs.fsf_-_@bsb.me.uk> <87r0gizzuo.fsf@nosuchdomain.example.com> <20240310101101.00001fd4@yahoo.com> <20240310100715.866@kylheku.com> <20240311185039.000066fc@yahoo.com> <87edcgzo7r.fsf@nosuchdomain.example.com> Injection-Date: Mon, 11 Mar 2024 17:58:03 -0000 (UTC) Injection-Info: dont-email.me; posting-host="2dfcac18fd004bfc05446b2cad7a6cb1"; logging-data="3941503"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BfX+3Nu3o7DwPEq8Cd4H/Y1VIQhN9p1E=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:abYAr1ghfBd3g+1LgpI5ZxmeN1U= Bytes: 2562 On 2024-03-11, Keith Thompson wrote: > Michael S writes: > [...] >> Is there any chance at all that on typical Linux machine (i.e. the one >> configured to overcommit virtual memory) strdup() returns NULL? >> If it was malloc() I'd say - no chance. For strdup() I'm less sure. > > strdup() calls malloc(), so strdup() can return NULL if and only if > malloc() can return NULL -- but with the additional constraint that you > first need to have a string argument to strdup() that's long enough to > cause a suffiently large argument to be passed to malloc(). > > One data point: On my Ubuntu system, malloc(SIZE_MAX) returns NULL for > very large arguments (over about 23 GiB in my quick and dirty test). I'm guessing that might be only be because of the overcommit_ratio value; i.e that allowing a 23 GiB increment in the allocated address space would bring the system over the currently configured overcommit ratio. -- TXR Programming Language: http://nongnu.org/txr Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal Mastodon: @Kazinator@mstdn.ca