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 strspn and strpbrk macros


glibc's <bits/string2.h> strspn and strpbrk macros are broken when the
second string is empty: they fail to evaluate the first string for its
side effects.  This may also apply to the <bits/string.h> versions.

Testcase: compile and run the following with optimization.

#include <string.h>
#include <stdlib.h>
#include <stdio.h>

int
main (void)
{
  const char *a = "abc";
  const char *b = a;
  puts ("Testing strspn.");
  strspn (b++, "");
  if (b != a + 1)
    abort ();
  puts ("Testing strpbrk.");
  strpbrk (b++, "");
  if (b != a + 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]