Path: utzoo!censor!geac!jtsv16!uunet!husc6!bloom-beacon!earth.cray.COM!jlf From: jlf@earth.cray.COM (John Freeman) Newsgroups: comp.windows.x Subject: Re: XtAppCreateShell. What am I doing wrong? Message-ID: <8906051426.AA08822@thelake.cray.com> Date: 5 Jun 89 14:26:17 GMT Organization: The Internet Lines: 50 > I notice that Xlib has code surrounded by #ifdefs on the preprocessor > variable "MALLOC_0_RETURNS_NULL". Very nice for SVIDish systems. I > also noticed (via the aforementioned error message) that the toolkit > was not quite so, > > I have no idea whether this could be the problem the original poster > was facing, but if so...just go into Xt/Alloc.c and make sure all the > allocation routines check for requests for 0 bytes, and pass on to > the libc equivalents requests for 1 (or more) bytes instead. The port of the toolkit by Cray Research does exactly what you suggest in Xt/Alloc.c. Here are the diffs: ------------------------------------------------------------------------------- diff -c ~/X11R3/lib/Xt/Alloc.c . *** /usr/earth3/jlf/X11R3/lib/Xt/Alloc.c Tue Sep 6 15:26:46 1988 --- ./Alloc.c Mon Dec 19 17:37:54 1988 *************** *** 41,46 **** --- 41,47 ---- unsigned size; { char *ptr; + if (size == 0) size = 1; if ((ptr = malloc(size)) == NULL) XtErrorMsg("allocError","malloc","XtToolkitError", "Cannot perform malloc", (String *)NULL, (Cardinal *)NULL); *************** *** 51,56 **** --- 52,58 ---- char *ptr; unsigned size; { + if (size == 0) size = 1; if (ptr == NULL) return(XtMalloc(size)); else if ((ptr = realloc(ptr, size)) == NULL) XtErrorMsg("allocError","realloc","XtToolkitError", *************** *** 62,67 **** --- 64,73 ---- unsigned num, size; { char *ptr; + if ((size == 0) || (num == 0)) { + size = 1; + num = 1; + } if ((ptr = calloc(num, size)) == NULL) XtErrorMsg("allocError","calloc","XtToolkitError", "Cannot perform calloc", (String *)NULL, (Cardinal *)NULL);