* linux strlen man page accepts NULL?
@ 2009-08-07 11:55 Jon Grant
[not found] ` <19ac3f7a0908070455s33ecb5efo6810eb7959df1f70-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Jon Grant @ 2009-08-07 11:55 UTC (permalink / raw)
To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA
Looking at this man page:
http://linux.die.net/man/3/strlen
Should it not mention that a NULL address is a valid param? Or is it
not a valid param? On most systems NULL is a special error pointer.
Cheers, Jon
--
To unsubscribe from this list: send the line "unsubscribe linux-man" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread[parent not found: <19ac3f7a0908070455s33ecb5efo6810eb7959df1f70-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: linux strlen man page accepts NULL? [not found] ` <19ac3f7a0908070455s33ecb5efo6810eb7959df1f70-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2009-08-07 19:51 ` Michael Kerrisk [not found] ` <cfd18e0f0908071251h27d2d7d6o4c7d8ae2a4c1913f-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Michael Kerrisk @ 2009-08-07 19:51 UTC (permalink / raw) To: Jon Grant; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA Jon, On Fri, Aug 7, 2009 at 1:55 PM, Jon Grant<jg-hus3n9K41k0@public.gmane.org> wrote: > Looking at this man page: > > http://linux.die.net/man/3/strlen > > Should it not mention that a NULL address is a valid param? Or is it > not a valid param? What makes you think it is a valid parameter? > On most systems NULL is a special error pointer. I don't understand what you mean with this last sentence. Please explain. Thanks, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Watch my Linux system programming book progress to publication! http://blog.man7.org/ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <cfd18e0f0908071251h27d2d7d6o4c7d8ae2a4c1913f-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: linux strlen man page accepts NULL? [not found] ` <cfd18e0f0908071251h27d2d7d6o4c7d8ae2a4c1913f-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2009-08-10 12:06 ` Jon Grant [not found] ` <19ac3f7a0908100506j7ec9933gec944f3b5bb92ef0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Jon Grant @ 2009-08-10 12:06 UTC (permalink / raw) To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA Hello 2009/8/7 Michael Kerrisk <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: > Jon, > > On Fri, Aug 7, 2009 at 1:55 PM, Jon Grant<jg-hus3n9K41k0@public.gmane.org> wrote: >> Looking at this man page: >> >> http://linux.die.net/man/3/strlen >> >> Should it not mention that a NULL address is a valid param? Or is it >> not a valid param? > > What makes you think it is a valid parameter? NULL points to 0x0, which could be mapped to something. On my embedded platform it is the beginning of the boot ROM. However typically 0x0 is an invalid address, in which case strlen should check for NULL, and return 0 e.g.: size_t strlen(const char *str) { const char *s; if(str == NULL) { return 0; } for (s = str; *s; ++s) ; return (s - str); } >> On most systems NULL is a special error pointer. > > I don't understand what you mean with this last sentence. Please explain. Well, the purpose of strlen is to count chars (excluding terminating '\0') but on most systems address 0x0 [which is what NULL is, (void*)0 ]. So if something is mapped by the hardware at 0x0 address then strlen could be used to count the number of characters at that location. However, on most systems his 0x0 address (NULL) indicates an invalid address. I am not on this mailing list, so please keep my email address in any replies. Best regards, Jon -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <19ac3f7a0908100506j7ec9933gec944f3b5bb92ef0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: linux strlen man page accepts NULL? [not found] ` <19ac3f7a0908100506j7ec9933gec944f3b5bb92ef0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2009-09-20 2:41 ` Michael Kerrisk [not found] ` <cfd18e0f0909191941s421596b1ne08da9906f4e4d5d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 0 siblings, 1 reply; 5+ messages in thread From: Michael Kerrisk @ 2009-09-20 2:41 UTC (permalink / raw) To: Jon Grant; +Cc: linux-man-u79uwXL29TY76Z2rM5mHXA Hello Jon, On Mon, Aug 10, 2009 at 2:06 PM, Jon Grant <jg-hus3n9K41k0@public.gmane.org> wrote: > Hello > > 2009/8/7 Michael Kerrisk <mtk.manpages-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org>: >> Jon, >> >> On Fri, Aug 7, 2009 at 1:55 PM, Jon Grant<jg-hus3n9K41k0@public.gmane.org> wrote: >>> Looking at this man page: >>> >>> http://linux.die.net/man/3/strlen >>> >>> Should it not mention that a NULL address is a valid param? Or is it >>> not a valid param? >> >> What makes you think it is a valid parameter? > > NULL points to 0x0, which could be mapped to something. D'oh! Sorry -- now I'm with you. Yes, it could. > On my embedded > platform it is the beginning of the boot ROM. However typically 0x0 is > an invalid address, in which case strlen should check for NULL, and > return 0 I don't think it should check for this. If the addres is invalid, it should be treated like any other invalid address -- usually a SIGSEGV results. > e.g.: > > size_t strlen(const char *str) > { > const char *s; > > if(str == NULL) > { > return 0; > } > > for (s = str; *s; ++s) > ; > return (s - str); > } > >>> On most systems NULL is a special error pointer. >> >> I don't understand what you mean with this last sentence. Please explain. > > Well, the purpose of strlen is to count chars (excluding terminating > '\0') but on most systems address 0x0 [which is what NULL is, (void*)0 > ]. > > So if something is mapped by the hardware at 0x0 address then strlen > could be used to count the number of characters at that location. > However, on most systems his 0x0 address (NULL) indicates an invalid > address. > > I am not on this mailing list, so please keep my email address in any replies. As far as I can see, there's nothing in the documentation that needs to be fixed. I'm doubtful that glibc's strlen() should be fixed either. I agree that mappings at 0x0 are a strange corner case that can produce unusual results in cases like these. Cheers, Michael -- Michael Kerrisk Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/ Watch my Linux system programming book progress to publication! http://blog.man7.org/ -- To unsubscribe from this list: send the line "unsubscribe linux-man" in the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info at http://vger.kernel.org/majordomo-info.html ^ permalink raw reply [flat|nested] 5+ messages in thread
[parent not found: <cfd18e0f0909191941s421596b1ne08da9906f4e4d5d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: linux strlen man page accepts NULL? [not found] ` <cfd18e0f0909191941s421596b1ne08da9906f4e4d5d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2009-09-22 6:43 ` Mike Frysinger 0 siblings, 0 replies; 5+ messages in thread From: Mike Frysinger @ 2009-09-22 6:43 UTC (permalink / raw) To: mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w Cc: Jon Grant, linux-man-u79uwXL29TY76Z2rM5mHXA [-- Attachment #1: Type: Text/Plain, Size: 717 bytes --] On Saturday 19 September 2009 22:41:41 Michael Kerrisk wrote: > On Mon, Aug 10, 2009 at 2:06 PM, Jon Grant wrote: > > On my embedded > > platform it is the beginning of the boot ROM. However typically 0x0 is > > an invalid address, in which case strlen should check for NULL, and > > return 0 > > I don't think it should check for this. If the addres is invalid, it > should be treated like any other invalid address -- usually a SIGSEGV > results. right. if 0 is a valid address, then strlen() should work. if it isnt valid and you called strlen() on it anyways, then your code sucks and it should crash. POSIX does not require special handling of any address, so neither should Linux. -mike [-- Attachment #2: This is a digitally signed message part. --] [-- Type: application/pgp-signature, Size: 836 bytes --] ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-09-22 6:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-07 11:55 linux strlen man page accepts NULL? Jon Grant
[not found] ` <19ac3f7a0908070455s33ecb5efo6810eb7959df1f70-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-08-07 19:51 ` Michael Kerrisk
[not found] ` <cfd18e0f0908071251h27d2d7d6o4c7d8ae2a4c1913f-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-08-10 12:06 ` Jon Grant
[not found] ` <19ac3f7a0908100506j7ec9933gec944f3b5bb92ef0-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-09-20 2:41 ` Michael Kerrisk
[not found] ` <cfd18e0f0909191941s421596b1ne08da9906f4e4d5d-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-09-22 6:43 ` Mike Frysinger
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox