[PATCH] Add strchrnul

Eric Blake eblake@redhat.com
Sat Apr 16 02:18:00 GMT 2011


On 04/15/2011 01:09 PM, Eric Blake wrote:
> On 03/27/2011 09:37 PM, Yaakov (Cygwin/X) wrote:
>> I'm attaching a patch and new C file to implement strchrnul, a GNU
>> extension.
>>
>> Corinna: patch for winsup being posted to cygwin-patches.
> 
>> char *
>> _DEFUN (strchrnul, (s1, i),
>> 	_CONST char *s1 _AND
>> 	int i)
>> {
>>   char *s = strchr(s1, i);
>>
>>   if (*s != NULL)
> 
> Oops.  That's a SEGV waiting to happen.

I'm pushing this:

2011-04-15  Eric Blake  <eblake@redhat.com>

	* libc/string/strchrnul.c (strchrnul): Fix strchrnul.

diff --git a/newlib/libc/string/strchrnul.c b/newlib/libc/string/strchrnul.c
index 59c7311..afeef43 100644
--- a/newlib/libc/string/strchrnul.c
+++ b/newlib/libc/string/strchrnul.c
@@ -43,7 +43,5 @@ _DEFUN (strchrnul, (s1, i),
 {
   char *s = strchr(s1, i);

-  if (*s != NULL)
-    return s;
-  return (char *)s1 + strlen(s1);
+  return s ? s : (char *)s1 + strlen(s1);
 }

-- 
Eric Blake   eblake@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://sourceware.org/pipermail/newlib/attachments/20110416/2212e1e9/attachment.sig>


More information about the Newlib mailing list