From: | Michael Wildpaner <mike(at)rainbow(dot)studorg(dot)tuwien(dot)ac(dot)at> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: [BUG/PATCH] backend crashes during authentication if |
Date: | 2003-12-05 22:28:01 |
Message-ID: | Pine.LNX.4.58.0312052221120.732@rainbow.studorg.tuwien.ac.at |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Hi,
On Fri, 5 Dec 2003, Tom Lane wrote:
> > Hm, Solaris' bsearch() fails on empty input? How bizarre.
>
> I was skeptical but apparently this is a known bug ...
> googling turned up a couple of references, eg
> http://www.opencm.org/pipermail/opencm-dev/2002-July/001077.html
in defense of Solaris' bsearch it should be said that it only breaks if
one passes NULL as the array base, a decidedly undefined (and unfriendly)
case. Passing an array with zero elements works as advertised. Btw, the
same happens on IRIX.
Best wishes, Mike
PS: A little program to demonstrate this: array with elements, empty
array, NULL pointer as base:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char strings[][4] = { "abc", "efg", "hij", "klm" };
typedef int (*cmp_t)(const void*, const void*);
int main(int argc, char**argv) {
char *s, *term = "hij";
s = bsearch(term, strings, sizeof(strings)/sizeof(char[4]),
sizeof(char*), (cmp_t) strcmp);
fprintf(stderr, "1: %s\n", (s != NULL) ? s : "<not found>");
s = bsearch(term, strings, 0, sizeof(char*), (cmp_t) strcmp);
fprintf(stderr, "2: %s\n", (s != NULL) ? s : "<not found>");
s = bsearch(term, NULL, 0, sizeof(char*), (cmp_t) strcmp);
fprintf(stderr, "3: %s\n", (s != NULL) ? s : "<not found>");
return 0;
}
Results:
$ ./a.out # Solaris 9
1: hij
2: <not found>
Segmentation Fault (core dumped)
$ ./a.out # IRIX 6.5
1: hij
2: <not found>
Segmentation fault (core dumped)
$ ./a.out # Linux with glibc 2.2.5
1: hij
2: <not found>
3: <not found>
$ ./a.out # OpenBSD 3.2
1: hij
2: <not found>
3: <not found>
--
Life is like a fire. DI Michael Wildpaner
Flames which the passer-by forgets. Ph.D. Student
Ashes which the wind scatters.
A man lived. -- Omar Khayyam
From | Date | Subject | |
---|---|---|---|
Next Message | Joe Conway | 2003-12-05 22:42:28 | Re: bytea, index and like operator again and detailed report |
Previous Message | Greg Stark | 2003-12-05 20:41:26 | Re: Proposed Query Planner TODO items |