NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/52778: strndup contains a reimplementation of strnlen



>Number:         52778
>Category:       lib
>Synopsis:       strndup contains a reimplementation of strnlen
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sun Dec 03 08:30:00 +0000 2017
>Originator:     Daniel Loffgren
>Release:        HEAD
>Organization:
>Environment:
NetBSD kudo 8.99.7 NetBSD 8.99.7 (GENERIC) #0: Thu Nov 30 21:39:35 UTC 2017  mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
While looking through the code of strndup, I noticed that the beginning of it contains a reimplementation of what strnlen already does. Shouldn't it defer to the function whose job is to do exactly that, ensuring that any optimizations made to strnlen benefit both?
>How-To-Repeat:

>Fix:
Index: lib/libc/string/strndup.c
===================================================================
RCS file: /cvsroot/src/lib/libc/string/strndup.c,v
retrieving revision 1.4 
diff -u -r1.4 strndup.c
--- lib/libc/string/strndup.c   3 Jul 2007 12:11:09 -0000   1.4
+++ lib/libc/string/strndup.c   15 Oct 2017 19:03:45 -0000
@@ -62,8 +62,7 @@

   _DIAGASSERT(str != NULL);

-   for (len = 0; len < n && str[len]; len++)
-       continue;
+   len = strnlen(str, n);

   if (!(copy = malloc(len + 1)))
       return (NULL);



Home | Main Index | Thread Index | Old Index