Re: May a string span multiple, independent objects?

Liste des GroupesRevenir à cs c 
Sujet : Re: May a string span multiple, independent objects?
De : jameskuyper (at) *nospam* alumni.caltech.edu (James Kuyper)
Groupes : comp.std.c
Date : 03. Jul 2024, 22:36:09
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v64g89$2c2c1$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla Thunderbird
On 7/3/24 17:08, Ben Bacarisse wrote:
James Kuyper <jameskuyper@alumni.caltech.edu> writes:
...
Because strlen() must take a pointer to 'a' (which is treated, for these
purposes, as a array of char of length 1), and increment it one past the
end of that array, and then dereference that pointer to check whether it
points as a null character, the behavior is undefined.
>
I think this is slightly misleading. It suggests that the UB comes from
something strlen /must/ do, but strlen must be thought of as a black
box. We can't base anyhting on a assumed implementation.
>
But our conclusion is correct because there is explicit wording covering
this case. The section on "String function conventions" (7.24.1)
states:
>
"If an array is accessed beyond the end of an object, the behavior is
undefined."

I'd forgotten about that; in fact, I'm not sure I've ever been aware of
that clause - but it makes sense. While C standard library routines
don't have to be written in C (many of them are in the standard library
precisely because they cannot be written in portable C), most of them
have limitations that make sense if you consider how they would have to
behave if written in C.



Date Sujet#  Auteur
3 Jul 24 * May a string span multiple, independent objects?13Vincent Lefevre
3 Jul 24 +* Re: May a string span multiple, independent objects?4Hans-Bernhard Bröker
3 Jul 24 i+- Re: May a string span multiple, independent objects?1Vincent Lefevre
3 Jul 24 i+- Re: May a string span multiple, independent objects?1James Kuyper
8 Aug 24 i`- Re: May a string span multiple, independent objects?1Tim Rentsch
3 Jul 24 +* Re: May a string span multiple, independent objects?7James Kuyper
3 Jul 24 i`* Re: May a string span multiple, independent objects?6Ben Bacarisse
3 Jul 24 i +- Re: May a string span multiple, independent objects?1James Kuyper
4 Jul 24 i `* Re: May a string span multiple, independent objects?4Vincent Lefevre
5 Jul 24 i  +- Re: May a string span multiple, independent objects?1Ben Bacarisse
5 Jul 24 i  +- Re: May a string span multiple, independent objects?1James Kuyper
8 Aug 24 i  `- Re: May a string span multiple, independent objects?1Tim Rentsch
5 Jul 24 `- Re: May a string span multiple, independent objects?1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal