linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonny Grant <jg@jguk.org>
To: Florian Weimer <fw@deneb.enyo.de>
Cc: linux-man <linux-man@vger.kernel.org>,
	Michael Kerrisk <mtk.manpages@gmail.com>
Subject: Re: strlen
Date: Sat, 5 Sep 2020 00:14:35 +0100	[thread overview]
Message-ID: <017a5a66-ba66-7cc8-c607-f851c2e54fc4@jguk.org> (raw)
In-Reply-To: <87lfhpgxf8.fsf@mid.deneb.enyo.de>



On 04/09/2020 20:21, Florian Weimer wrote:
> * Jonny Grant:
> 
>> Hello
>>
>> https://man7.org/linux/man-pages/man3/strlen.3.html
>>
>> Is it possible to clarify :-
>>
>> * glibc will SIGSEGV if 's' is NULL
>> * there are no ERROR returns
> 
> That would be misleading.  Whether strlen (NULL) is undefined also
> depends on the compiler.  They know that the argument cannot be zero
> and optimize accordingly.
> 

Hi,

Do you know a compiler that has a different behaviour? I only tested gcc and clang. How would a compiler optimise?

The header has non-null attribute for the compiler (ie gcc) to use to give a nice warning

str.c:6:8: warning: null argument where non-null required (argument 1) [-Wnonnull]
    6 | return strlen(NULL);

However, if the implementation gets NULL it still crashes.

I was using -fno-builtin-strlen so it was glibc, but the __builtin_strlen ha SEGV just like glibc

clang is the same as gcc.

So it feels like it's pretty clear, there is no NULL check, can this be documented? 

Jonny

  reply	other threads:[~2020-09-04 23:14 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-04 18:01 strlen Jonny Grant
2020-09-04 19:21 ` strlen Florian Weimer
2020-09-04 23:14   ` Jonny Grant [this message]
2020-09-05  7:12     ` strlen Florian Weimer
2021-07-06 20:30       ` strlen Jonny Grant
2021-07-06 22:11         ` strlen Florian Weimer
2021-07-07 11:36           ` strlen Jonny Grant
2021-07-07 12:22             ` strlen Alejandro Colomar (man-pages)
2021-07-07 12:31               ` strlen Alejandro Colomar (man-pages)
2021-07-07 13:31                 ` strlen Jonny Grant
2021-07-07 16:57                   ` strlen Alejandro Colomar (man-pages)
2021-07-07 17:23                     ` strlen Alejandro Colomar (man-pages)
2021-07-07 17:33                       ` strlen Alejandro Colomar (man-pages)
2021-07-09 13:48                         ` strlen Jonny Grant
2021-07-08 10:07                     ` strlen Jonny Grant
2021-07-08 11:06                       ` strlen Alejandro Colomar (man-pages)
2021-07-08 12:13                         ` strlen Xi Ruoyao
2021-07-08 23:49                         ` strlen Segher Boessenkool
2021-07-09 13:54                           ` strlen Jonny Grant
2021-07-09 14:17                             ` strlen Alejandro Colomar (man-pages)
2021-07-09 16:11                               ` strlen Xi Ruoyao
2021-07-10  1:00                               ` strlen Segher Boessenkool
2021-07-09 10:50                         ` strlen Jonny Grant
2021-07-09 11:27                           ` strlen Alejandro Colomar (man-pages)
2021-07-09 11:43                             ` strlen Alejandro Colomar (man-pages)
     [not found]                         ` <1627912755.3783669.1625745946723@mail.yahoo.com>
     [not found]                           ` <59a70222-a46f-1e65-c9db-6c9e577c8adc@126.com>
2021-07-09 17:26                             ` strlen Martin Sebor
2021-07-09 20:19                               ` strlen Alejandro Colomar (man-pages)
2021-07-09 20:44                     ` strlen Jonny Grant
2021-07-10 18:37                       ` strlen Alejandro Colomar (man-pages)
2021-07-10 20:49                         ` strlen Jonny Grant
2021-07-10 21:36                           ` strlen Alejandro Colomar (man-pages)
2021-07-12 21:16                             ` strlen Jonny Grant

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=017a5a66-ba66-7cc8-c607-f851c2e54fc4@jguk.org \
    --to=jg@jguk.org \
    --cc=fw@deneb.enyo.de \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).