Deutsch English Français Italiano |
<vsldc8$28l7$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!3.eu.feeder.erje.net!feeder.erje.net!news.tomockey.net!news.samoylyk.net!weretis.net!feeder9.news.weretis.net!news.quux.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: David Brown <david.brown@hesbynett.no> Newsgroups: comp.lang.c Subject: Re: A question regarding C string functions Date: Thu, 3 Apr 2025 09:29:12 +0200 Organization: A noiseless patient Spider Lines: 34 Message-ID: <vsldc8$28l7$1@dont-email.me> References: <vsjujs$21log$1@dont-email.me> <20250402112547.50@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 03 Apr 2025 09:29:13 +0200 (CEST) Injection-Info: dont-email.me; posting-host="d65639e364606db0746acbec737df138"; logging-data="74407"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Wey4EW9R7EY5+9+hso+dCXElFMzS9yJE=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Cancel-Lock: sha1:Nd+iF8Pf4QGCtHK4H2OWkCribBA= Content-Language: en-GB In-Reply-To: <20250402112547.50@kylheku.com> Bytes: 2513 On 02/04/2025 20:33, Kaz Kylheku wrote: > It gets more verbose and indented, but the null treatment is > consistently there. > In the current working draft for the future standard after C23, it says: """ Where an argument declared as size_t n specifies the length of the array for a function, n can have the value zero on a call to that function. Unless explicitly stated otherwise in the description of a particular function in this subclause, pointer arguments on such a call may be null pointers. On such a call, a function that locates a character finds no occurrence, a function that compares two character sequences returns zero, and a function that copies characters copies zero characters. """ And the change list includes : """ Allowed zero-length operations on null pointers. """ That sounds like if you call something like "strncpy" with a maximum length of 0, then null pointers are safe - if nothing is moved, copied, or searched, then the pointer is not dereferenced and the behaviour is defined. It seems likely to me that this is the behaviour you would get with most current implementations of the library functions - but of course that is not something to rely on until you are using post-C23 standard tools.