[patch] shell/ash.c: -W<something> warnings
Denys Vlasenko
vda.linux at googlemail.com
Sun May 18 14:06:28 UTC 2008
On Sunday 18 May 2008 14:17, Cristian Ionescu-Idbohrn wrote:
> This patch reduces the number of compiler warnings from 39 (svn) to 7.
> Warning options used:
>
> -Wconversion -Wformat=2 -W -Wbad-function-cast -Wall -Wpointer-arith
What do you think about first finishing with -Wall warnings only,
adding -Wall to standard bbox buildd options (in Makefile.flags file),
and only then adding more -W opts?
> I did run the tests under shell/ash_test and got identical results as with
> the current svn. Please review.
You should minimize the number of type casts used.
- g_stacknxt = memcpy(p, oldspace, oldlen);
+ g_stacknxt = memcpy(p, oldspace, (size_t)oldlen);
I don't like it.
You should change "int oldlen" to "size_t oldlen" here:
int oldlen = g_stacknleft; <<===
char *p = stalloc(newlen);
/* free the space we just allocated */
g_stacknxt = memcpy(p, oldspace, oldlen);
because g_stacknleft is already size_t.
Then you don't need the cast.
These changes:
-#define grabstackstr(p) stalloc((char *)(p) - (char *)stackblock())
+#define grabstackstr(p) stalloc((size_t)((char *)(p) - (char *)stackblock()))
- memcpy(q, start, p - start);
+ memcpy(q, start, (size_t)(p - start));
- memtodest(p, i, syntax, quotes);
+ memtodest(p, (size_t)i, syntax, quotes);
- memmove(startp, loc, str - loc);
+ memmove(startp, loc, (size_t)(str - loc));
- memtodest(p, len, syntax, quotes);
+ memtodest(p, (size_t)len, syntax, quotes);
- expdir = ckmalloc(i < 2048 ? 2048 : i); /* XXX */
+ expdir = ckmalloc((size_t)(i < 2048 ? 2048 : i)); /* XXX */
etc, don't look like improvement to me.
The rest is applied.
--
vda
More information about the busybox
mailing list