scandir() documented incorrectly
Jim Rees
rees at apollo.uucp
Wed Jul 3 04:05:51 AEST 1985
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)
More information about the Comp.bugs.4bsd.ucb-fixes
mailing list