[PATCH v2] top: fix and merge code to parse /proc/meminfo
Timo Teras
timo.teras at iki.fi
Mon Jul 28 15:25:36 UTC 2014
On Mon, 28 Jul 2014 16:27:37 +0200
Ralf Friedl <Ralf.Friedl at online.de> wrote:
> Timo Teras wrote:
> > On Sun, 27 Jul 2014 21:50:28 +0200
> > Denys Vlasenko <vda.linux at googlemail.com> wrote:
> >> Applied, thanks!
> > Thanks, though I noticed now a weirdness that did not happen before.
> >
> > +static void parse_meminfo(unsigned long meminfo[MI_MAX])
> > +{
> > ...
> > + memset(meminfo, 0, sizeof(meminfo));
> >
> > Seems to not work. The sizeof() return something small. Probably
> > sizeof(unsigned long*).
> >
> > Is my compiler broken, or is the expected behaviour?
> That is the expected behaviour. A parameter declaration of unsigned
> long[] is that same as unsigned long*.
So something like:
diff --git a/procps/top.c b/procps/top.c
index 62f9421..119c32b 100644
--- a/procps/top.c
+++ b/procps/top.c
@@ -536,7 +536,7 @@ static void parse_meminfo(unsigned long meminfo[MI_MAX])
FILE *f;
int i;
- memset(meminfo, 0, sizeof(meminfo));
+ memset(meminfo, 0, MI_MAX*sizeof(meminfo[0]));
f = xfopen_for_read("meminfo");
while (fgets(buf, sizeof(buf), f) != NULL) {
char *c = strchr(buf, ':');
Would be needed to fix it.
More information about the busybox
mailing list