DragonFly BSD
DragonFly submit List (threaded) for 2006-06
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: Add strndup


From: Andreas Hauser <andy@xxxxxxxxxxxxxxx>
Date: 21 Jun 2006 08:53:37 +0200

dillon wrote @ Tue, 20 Jun 2006 23:27:14 -0700 (PDT):
> 
> :andy wrote @ 20 Jun 2006 21:44:17 +0200:
> :
> :Fixed the off-by-one:
> :http://ftp.fortunaty.net/DragonFly/inofficial/patches/strndup.patch
> 
>     Umm.  That code is broken.  len is only the maximum allowed length,
>     the actual string may be smaller.
> 
>     so e.g. someone might do:  strndup("fubar", 16384).  The returned
>     string should only be 'fubar\0', and only 6 bytes should be allocated,
>     not 16384.

But when it works like that, one does not save the strlen.
Hence i see the dislike for the function.
I would like to have one, that does not work like that.
Is there already a name for it?

-- 
Andy



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