Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #58583

Re: Code for strlen

From Kaz Kylheku <kaz@kylheku.com>
Newsgroups comp.lang.c
Subject Re: Code for strlen
Date 2015-03-21 16:09 +0000
Organization Aioe.org NNTP Server
Message-ID <20150321090457.184@kylheku.com> (permalink)
References <mek3a7$rvp$1@speranza.aioe.org>

Show all headers | View raw


On 2015-03-21, jacob navia <jacob@jacob.remcomp.fr> wrote:
> I have spent a week trying to get the strlen function right. It is 
> very complicated and I am still not sure if it produces the correct 
> results in all cases. Maybe we can together make a strlen function 
> that is better than what gcc has to offer ( :-) )
>
> Interesting issues were what happens when NULL is passed to strlen? I 
> could not find any reference to the standard and all page references 
> that I got so far were showing completely different content.

Have you looked in C99 7.1.4 Use of Library Functions.

"Each of the following statements applies unless explicitly stated otherwise in
                                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the detailed descriptions that follow: 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 promotion) not expected by a function with variable number of
arguments, the behavior is undefined."
           ^^^^^^^^^^^^^^^^^^^^^^^^^^

So, for any function that has a pointer argument, unless the description of
the function allows a null pointer, it is undefined behavior to pass one.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Code for strlen jacob navia <jacob@jacob.remcomp.fr> - 2015-03-21 16:38 +0100
  Re: Code for strlen Kaz Kylheku <kaz@kylheku.com> - 2015-03-21 16:09 +0000
    Re: Code for strlen Greg Martin <greg.at.softsprocket@dot.com> - 2015-03-21 16:35 +0000
      Re: Code for strlen Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-21 09:41 -0700
        Re: Code for strlen Lőrinczy Zsigmond <nospam@for.me> - 2015-03-21 20:27 +0100
      Re: Code for strlen Kaz Kylheku <kaz@kylheku.com> - 2015-03-21 17:13 +0000
  Re: Code for strlen Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-03-21 09:35 -0700
    Re: Code for strlen Keith Thompson <kst-u@mib.org> - 2015-03-21 15:01 -0700
  Re: Code for strlen jacob navia <jacob@jacob.remcomp.fr> - 2015-03-21 18:25 +0100
    Re: Code for strlen Aleksandar Kuktin <akuktin@gmail.com> - 2015-03-21 22:46 +0000

csiph-web