Re: A question regarding C string functions

Liste des GroupesRevenir à cl c 
Sujet : Re: A question regarding C string functions
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.lang.c
Date : 03. Apr 2025, 05:36:05
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vsl37l$3f1pl$2@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 4/2/25 14:11, Lew Pitcher wrote:
I cannot find any definitive statement in my copies of the various
C language standards that addresses the behaviour of the C string
functions when given a NULL pointer.
>
Specifically, what does the C standard dictate about the behaviour of
strrchr(NULL,'/')
but the question could apply to any of the string functions
(strlen(NULL), etc.)
>
My gut impression is that
strrchr(NULL,'/'), etc
invoke undefined behaviour, and should be avoided.
>
Can anyone comment?
>

In n3096.pdf (dated )
"If an argument to a function has an invalid value (such as a value
outside the domain of the function, or a pointer outside the address
space of the program, or a null pointer, or a pointer to non-modifiable
storage when the corresponding parameter is not const-qualified) or a
type (after default argument promotion) not expected by a function with
a variable number of arguments, the behavior is undefined." (7.1.4p1)

But keep in mind that this general rule can be overridden by explict
statements defining the behavior of a function when passed a null
pointer. Such statements occur in the descriptions of a dozens of
functions. I started compiling a list, but gave up.


Date Sujet#  Auteur
2 Apr 25 * A question regarding C string functions8Lew Pitcher
2 Apr 25 +* Re: A question regarding C string functions3Kaz Kylheku
2 Apr 25 i+- Re: A question regarding C string functions1Lew Pitcher
3 Apr 25 i`- Re: A question regarding C string functions1David Brown
3 Apr 25 +* Re: A question regarding C string functions3Tim Rentsch
3 Apr 25 i+- Re: A question regarding C string functions1Lew Pitcher
3 Apr 25 i`- Re: A question regarding C string functions1Ethan Carter
3 Apr 25 `- Re: A question regarding C string functions1James Kuyper

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal