[PATCH] ls: clean up
Shaun Jackman
sjackman at gmail.com
Thu Apr 27 17:06:11 UTC 2006
On 4/27/06, Vladimir N. Oleynik <dzo at simtreas.ru> wrote:
> Shaun,
>
> >>>You might find dmalloc helps to ferret out these subtle
> >>>(or not-so-subtle) bugs down.
> >>
> >>Your last patch strange for me. May be #if DMALLOC more good?
> >
> >
> > Please give more explanation. Strange how?
>
> prt = (ptr_type)1;
> its special strange code for mainstream programming.
Fair enough. How about this patch then?
The issue with using allocated as the next point as well as the
allocated flag, was that the tail of the list has the next element
pointing to NULL, which is a false allocated flag when it should be
true. I pointed the allocated flag of the tail element back to the
head.
Cheers,
Shaun
--- coreutils/ls.c- 2006-04-25 10:38:29.000000000 -0600
+++ coreutils/ls.c 2006-04-27 11:00:48.000000000 -0600
@@ -38,7 +38,6 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
@@ -603,6 +602,10 @@
dnp = dnalloc(nfiles);
for (i = 0, cur = dn; i < nfiles; i++) {
dnp[i] = cur; /* save pointer to node in array */
+ if (cur->allocated == NULL) {
+ cur->allocated = dn;
+ break;
+ }
cur = cur->allocated;
}
*pnfiles = nfiles;
@@ -1124,12 +1127,16 @@
shellsort(dnf, dnfiles);
#endif
showfiles(dnf, dnfiles);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(dnf);
}
if (dndirs > 0) {
#ifdef CONFIG_FEATURE_LS_SORTFILES
shellsort(dnd, dndirs);
#endif
showdirs(dnd, dndirs, dnfiles == 0);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(dnd);
}
}
if (ENABLE_FEATURE_CLEAN_UP)
-------------- next part --------------
--- coreutils/ls.c- 2006-04-25 10:38:29.000000000 -0600
+++ coreutils/ls.c 2006-04-27 11:00:48.000000000 -0600
@@ -38,7 +38,6 @@
#include <sys/types.h>
#include <sys/stat.h>
-#include <stdio.h>
#include <unistd.h>
#include <dirent.h>
#include <errno.h>
@@ -603,6 +602,10 @@
dnp = dnalloc(nfiles);
for (i = 0, cur = dn; i < nfiles; i++) {
dnp[i] = cur; /* save pointer to node in array */
+ if (cur->allocated == NULL) {
+ cur->allocated = dn;
+ break;
+ }
cur = cur->allocated;
}
*pnfiles = nfiles;
@@ -1124,12 +1127,16 @@
shellsort(dnf, dnfiles);
#endif
showfiles(dnf, dnfiles);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(dnf);
}
if (dndirs > 0) {
#ifdef CONFIG_FEATURE_LS_SORTFILES
shellsort(dnd, dndirs);
#endif
showdirs(dnd, dndirs, dnfiles == 0);
+ if (ENABLE_FEATURE_CLEAN_UP)
+ free(dnd);
}
}
if (ENABLE_FEATURE_CLEAN_UP)
More information about the busybox
mailing list