Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 Apollo 5/13/85; site apollo.uucp Path: utzoo!watmath!clyde!bonnie!akgua!whuxlm!harpo!decvax!wanginst!apollo!rees From: rees@apollo.uucp (Jim Rees) Newsgroups: net.bugs.4bsd Subject: Re: scandir() documented incorrectly Message-ID: <277b559b.1de6@apollo.uucp> Date: Tue, 2-Jul-85 14:05:51 EDT Article-I.D.: apollo.277b559b.1de6 Posted: Tue Jul 2 14:05:51 1985 Date-Received: Fri, 5-Jul-85 07:10:01 EDT References: <2436@mordor.UUCP> Organization: Apollo Computer, Chelmsford, Mass. Lines: 79 While you're at it, fix the realloc logic. It can't ever work, because once it runs out of space, it realloc's every time through the loop. And it thinks it's smarter than it really is about how big a directory entry should be. It shouldn't have numbers like "24" hard wired into the source code. *************** *** 55,61 for (cp1 = p->d_name, cp2 = d->d_name; *cp1++ = *cp2++; ); /* * Check to make sure the array has space left and ! * realloc the maximum size. */ if (++nitems >= arraysz) { names = (struct direct **)realloc((char *)names, --- 70,76 ----- for (cp1 = p->d_name, cp2 = d->d_name; *cp1++ = *cp2++; ); /* * Check to make sure the array has space left and ! * realloc some more. */ if (nitems >= arraysz) { arraysz += arraysz / 2 + 2; *************** *** 57,63 * Check to make sure the array has space left and * realloc the maximum size. */ ! if (++nitems >= arraysz) { names = (struct direct **)realloc((char *)names, (stb.st_size/12) * sizeof(struct direct *)); if (names == NULL) --- 72,79 ----- * Check to make sure the array has space left and * realloc some more. */ ! if (nitems >= arraysz) { ! arraysz += arraysz / 2 + 2; names = (struct direct **)realloc((char *)names, arraysz * sizeof(struct direct *)); if (names == NULL) *************** *** 59,65 */ if (++nitems >= arraysz) { names = (struct direct **)realloc((char *)names, ! (stb.st_size/12) * sizeof(struct direct *)); if (names == NULL) return(-1); } --- 75,81 ----- if (nitems >= arraysz) { arraysz += arraysz / 2 + 2; names = (struct direct **)realloc((char *)names, ! arraysz * sizeof(struct direct *)); if (names == NULL) return(-1); } *************** *** 63,69 if (names == NULL) return(-1); } ! names[nitems-1] = p; } closedir(dirp); if (nitems && dcomp != NULL) --- 79,85 ----- if (names == NULL) return(-1); } ! names[nitems++] = p; } closedir(dirp); if (nitems && dcomp != NULL)