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

  • From: "tqh" <trac@xxxxxxxxxxxx>
  • Date: Wed, 25 Apr 2012 14:50:37 -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 tqh):

 The code can be simplified by changing
 {{{
 34          if (((addr_t)src & 3) != 0) {
 }}}
 to
 {{{
 34          if (((addr_t)src & 3) == 0) {
 }}}
 removing line 35 to 45
 and moving
 {{{
         // Deal with the remainder.
         60              while (count-- != 0) {
         61                  if ((*dest++ = *src++) == '\0') {
         62                      memset(dest, '\0', count);
         63                      return tmp;
         64                  }
         65              }
 }}}

 Also I'm not sure whether we want to do source alignment (on x86 at
 least).

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

Other related posts: