This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Broken strncat macro


glibc's strncat macro is broken on i686-linux when you define
__USE_STRING_INLINES: it fails to append the terminating null character
when the length to concatenate is less than the string length.  This
applies both to <bits/string.h>'s version and to that in <bits/string2.h>
if _HAVE_STRING_ARCH_strchr is defined.

Testcase:

#define __USE_STRING_INLINES
#include <string.h>
#include <stdlib.h>

char d[3] = "\0\1\2";

int
main (void)
{
  strncat (d, "\5\6", 1);
  if (d[0] != 5 || d[1] != 0 || d[2] != 2)
    abort ();
  exit (0);
}

-- 
Joseph S. Myers
jsm28@cam.ac.uk


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]