[haiku-bugs] Re: [Haiku] #8481: strncpy doesn't pad the destination string with NULs

  • From: "korli" <trac@xxxxxxxxxxxx>
  • Date: Thu, 19 Apr 2012 11:50:51 -0000

#8481: strncpy doesn't pad the destination string with NULs
---------------------------------+----------------------------
   Reporter:  hamish             |      Owner:  axeld
       Type:  bug                |     Status:  new
   Priority:  normal             |  Milestone:  R1
  Component:  System/libroot.so  |    Version:  R1/Development
 Resolution:                     |   Keywords:  strncpy
 Blocked By:                     |   Blocking:
Has a Patch:  1                  |   Platform:  All
---------------------------------+----------------------------

Comment (by korli):

 Replying to [comment:2 hamish]:
 > On x86, gcc2+4 O0/O2/O3, zeroing everything beforehand is faster than
 zeroing the remainder afterwards in most cases

 Hmm, surely correct when the source string is empty, but incorrect when
 the source string has the specified length or more.

 I think you should better memset afterward with dest and count, which
 should already have the correct values (unless I'm mistaken).

-- 
Ticket URL: <http://dev.haiku-os.org/ticket/8481#comment:3>
Haiku <http://dev.haiku-os.org>
Haiku - the operating system.

Other related posts: