public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug other/50277] New: strndup should use strnlen instead of strlen @ 2011-09-02 16:40 ivan.tubert at gmail dot com 2011-09-02 16:45 ` [Bug other/50277] " pinskia at gcc dot gnu.org ` (3 more replies) 0 siblings, 4 replies; 5+ messages in thread From: ivan.tubert at gmail dot com @ 2011-09-02 16:40 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50277 Bug #: 50277 Summary: strndup should use strnlen instead of strlen Classification: Unclassified Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: other AssignedTo: unassigned@gcc.gnu.org ReportedBy: ivan.tubert@gmail.com Regarding strndup (const char *s, size_t n): strndup is using strlen to get the length of s, in order to decide whether to allocate n+1 characters or strlen(s)+1. This is inefficient. Imagine that s is one googol characters long, and I call strndup(s,3) because I want a duplicate of up to the first three characters. Yet strlen will go all the way to the end of s, just to find that it is longer than 3 characters! I suggest using strnlen instead. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug other/50277] strndup should use strnlen instead of strlen 2011-09-02 16:40 [Bug other/50277] New: strndup should use strnlen instead of strlen ivan.tubert at gmail dot com @ 2011-09-02 16:45 ` pinskia at gcc dot gnu.org 2011-09-02 16:52 ` ivan.tubert at gmail dot com ` (2 subsequent siblings) 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2011-09-02 16:45 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50277 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-09-02 16:45:15 UTC --- strndup is part of the libc that comes from your OS and not part of GCC. Most likely you wanted to file this as a glibc bug. ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug other/50277] strndup should use strnlen instead of strlen 2011-09-02 16:40 [Bug other/50277] New: strndup should use strnlen instead of strlen ivan.tubert at gmail dot com 2011-09-02 16:45 ` [Bug other/50277] " pinskia at gcc dot gnu.org @ 2011-09-02 16:52 ` ivan.tubert at gmail dot com 2011-09-02 16:55 ` ivan.tubert at gmail dot com 2011-09-02 16:59 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: ivan.tubert at gmail dot com @ 2011-09-02 16:52 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50277 --- Comment #2 from Ivan Tubert-Brohman <ivan.tubert at gmail dot com> 2011-09-02 16:51:42 UTC --- On Fri, Sep 2, 2011 at 12:45 PM, pinskia at gcc dot gnu.org <gcc-bugzilla@gcc.gnu.org> wrote: > --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-09-02 16:45:15 UTC --- > strndup is part of the libc that comes from your OS and not part of GCC. Most > likely you wanted to file this as a glibc bug. Thanks, I got confused because I found the code in the gcc repository. (I was looking at http://gcc.gnu.org/viewcvs/trunk/libiberty/strndup.c?view=markup ) ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug other/50277] strndup should use strnlen instead of strlen 2011-09-02 16:40 [Bug other/50277] New: strndup should use strnlen instead of strlen ivan.tubert at gmail dot com 2011-09-02 16:45 ` [Bug other/50277] " pinskia at gcc dot gnu.org 2011-09-02 16:52 ` ivan.tubert at gmail dot com @ 2011-09-02 16:55 ` ivan.tubert at gmail dot com 2011-09-02 16:59 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: ivan.tubert at gmail dot com @ 2011-09-02 16:55 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50277 --- Comment #3 from Ivan Tubert-Brohman <ivan.tubert at gmail dot com> 2011-09-02 16:55:07 UTC --- And the code in glibc already uses strnlen. Sorry about that. Please close the ticket unless you deem necessary to modify the version in libiberty/strndup.c ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug other/50277] strndup should use strnlen instead of strlen 2011-09-02 16:40 [Bug other/50277] New: strndup should use strnlen instead of strlen ivan.tubert at gmail dot com ` (2 preceding siblings ...) 2011-09-02 16:55 ` ivan.tubert at gmail dot com @ 2011-09-02 16:59 ` pinskia at gcc dot gnu.org 3 siblings, 0 replies; 5+ messages in thread From: pinskia at gcc dot gnu.org @ 2011-09-02 16:59 UTC (permalink / raw) To: gcc-bugs http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50277 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |RESOLVED Resolution| |INVALID --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> 2011-09-02 16:58:48 UTC --- Well that is the portable version of strndup, GCC uses it only once but it is only will ever be called with a string which has a null char. Also strnlen is not portable either. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-09-02 16:59 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-09-02 16:40 [Bug other/50277] New: strndup should use strnlen instead of strlen ivan.tubert at gmail dot com 2011-09-02 16:45 ` [Bug other/50277] " pinskia at gcc dot gnu.org 2011-09-02 16:52 ` ivan.tubert at gmail dot com 2011-09-02 16:55 ` ivan.tubert at gmail dot com 2011-09-02 16:59 ` pinskia at gcc dot gnu.org
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 read-only IMAP folder(s) and NNTP newsgroup(s).