From d9c27253ce333e2086b2d758b42dc3ecb8b34c3d Mon Sep 17 00:00:00 2001 From: Wolfgang Denk Date: Sun, 20 Jun 2010 17:14:14 +0200 Subject: Make *printf() return "int" instead of "void" Change the return type of the *printf() functions to the standard "int"; no changes are needed but returning the already available length count. This will save a few additional strlen() calls later... Signed-off-by: Wolfgang Denk --- include/exports.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/exports.h') diff --git a/include/exports.h b/include/exports.h index c3a5d2f..9588bc9 100644 --- a/include/exports.h +++ b/include/exports.h @@ -11,14 +11,14 @@ int getc(void); int tstc(void); void putc(const char); void puts(const char*); -void printf(const char* fmt, ...); +int printf(const char* fmt, ...); void install_hdlr(int, interrupt_handler_t*, void*); void free_hdlr(int); void *malloc(size_t); void free(void*); void __udelay(unsigned long); unsigned long get_timer(unsigned long); -void vprintf(const char *, va_list); +int vprintf(const char *, va_list); void do_reset (void); unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base); char *getenv (char *name); -- cgit v1.1 From 54841ab50c20d6fa6c9cc3eb826989da3a22d934 Mon Sep 17 00:00:00 2001 From: Wolfgang Denk Date: Mon, 28 Jun 2010 22:00:46 +0200 Subject: Make sure that argv[] argument pointers are not modified. The hush shell dynamically allocates (and re-allocates) memory for the argument strings in the "char *argv[]" argument vector passed to commands. Any code that modifies these pointers will cause serious corruption of the malloc data structures and crash U-Boot, so make sure the compiler can check that no such modifications are being done by changing the code into "char * const argv[]". This modification is the result of debugging a strange crash caused after adding a new command, which used the following argument processing code which has been working perfectly fine in all Unix systems since version 6 - but not so in U-Boot: int main (int argc, char **argv) { while (--argc > 0 && **++argv == '-') { /* ====> */ while (*++*argv) { switch (**argv) { case 'd': debug++; break; ... default: usage (); } } } ... } The line marked "====>" will corrupt the malloc data structures and usually cause U-Boot to crash when the next command gets executed by the shell. With the modification, the compiler will prevent this with an error: increment of read-only location '*argv' N.B.: The code above can be trivially rewritten like this: while (--argc > 0 && **++argv == '-') { char *arg = *argv; while (*++arg) { switch (*arg) { ... Signed-off-by: Wolfgang Denk Acked-by: Mike Frysinger --- include/exports.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/exports.h') diff --git a/include/exports.h b/include/exports.h index 9588bc9..1d79a31 100644 --- a/include/exports.h +++ b/include/exports.h @@ -35,7 +35,7 @@ int i2c_read (uchar, uint, int , uchar* , int); #endif #include -void app_startup(char **); +void app_startup(char * const *); #endif /* ifndef __ASSEMBLY__ */ -- cgit v1.1