This is the mail archive of the libc-alpha@sourceware.org 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]
Other format: [Raw text]

Re: [PATCH] stdlib-bsearch: middle element calculation may overflow


I don't see why any of the array elements need to be valid, it's
purely a test of void*/char* arithmetic.

int c(const void *a, const void *b)
{
  return (b > a) ? -1 : ((b < a) ? 1 : 0);
}

int main(void)
{
  printf("%p\n", bsearch((void *)0xfffffffffffffffeULL, NULL,
0xffffffffffffffffULL, 1, c));

  return 0;
}

works with the patch, and fails without it, on x86_64. (I'm not sure
whether the behavior is defined by the C standard, but I'm pretty sure
it's defined by the x86_64 ABI).


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