Mail Archives: geda-user/2014/09/23/23:49:02
On Wed, 24 Sep 2014, Kai-Martin Knaak wrote:
> Girvin Herr wrote:
>
>> If there are warnings, what
>> other, worse bugs are in there?
>
> Lets see...
> <set-gcc-flags-to -W -Wall -ansi -pedantic>
> <build guile>
> <grep log> (6k lines(!)) there are actually quite a few warnings:
>
> (...)
> read.c: In function 'try_read_ci_chars':
> read.c:983:3: warning: implicit declaration of function 'alloca' [-Wimplicit-function-declaration]
> char *chars_read = alloca (num_chars_wanted);
> ^
> read.c:983:22: warning: incompatible implicit declaration of built-in function 'alloca'
> char *chars_read = alloca (num_chars_wanted);
> ^
#include <alloca.h> (or something else depending on your libc there) to
get the declaration of alloca(). Alternatively an ugly workaround is to
declare it manually before the call (in case it's impossible to determine
which .h to include or auto* gets in the way):
extern void *alloca(size_t size);
The extern is optional. Manual declaration of such builtin may cause
problems if the C compiler is clever enough.
Background:
On many systems this is a serious problem: without an explicit
declaration, alloca() will default to return int which is then casted to a
pointer. This happens to work on some systems with sizeof(int) ==
sizeof(char *), but will almost always break on others. With gcc a 32 bit
i386 is normally in the first group while x86_64 is in the second.
>
> posix.c: In function 'scm_execl':
> posix.c:1144:3: warning: passing argument 2 of 'execv' from incompatible pointer type
> execv (exec_file, exec_argv);
> ^
> In file included from /usr/local/src/mxe/usr/i686-pc-mingw32.static/include/unistd.h:13:0,
> from ../lib/unistd.h:40,
> from posix.c:50:
> /usr/local/src/mxe/usr/i686-pc-mingw32.static/include/process.h:118:42: note: expected 'const char * const*' but argument is of type 'char **'
> _CRTIMP intptr_t __cdecl __MINGW_NOTHROW execv (const char*, const char* const*);
> ^
> posix.c: In function 'scm_execlp':
> posix.c:1173:3: warning: passing argument 2 of 'execvp' from incompatible pointer type
> execvp (exec_file, exec_argv);
> ^
> In file included from /usr/local/src/mxe/usr/i686-pc-mingw32.static/include/unistd.h:13:0,
> from ../lib/unistd.h:40,
> from posix.c:50:
> /usr/local/src/mxe/usr/i686-pc-mingw32.static/include/process.h:120:42: note: expected 'const char * const*' but argument is of type 'char **'
> _CRTIMP intptr_t __cdecl __MINGW_NOTHROW execvp (const char*, const char* const*);
> ^
> posix.c: In function 'scm_execle':
> posix.c:1207:3: warning: passing argument 2 of 'execve' from incompatible pointer type
> execve (exec_file, exec_argv, exec_env);
> ^
> In file included from /usr/local/src/mxe/usr/i686-pc-mingw32.static/include/unistd.h:13:0,
> from ../lib/unistd.h:40,
> from posix.c:50:
> /usr/local/src/mxe/usr/i686-pc-mingw32.static/include/process.h:119:42: note: expected 'const char * const*' but argument is of type 'char **'
> _CRTIMP intptr_t __cdecl __MINGW_NOTHROW execve (const char*, const char* const*, const char* const*);
> ^
> posix.c:1207:3: warning: passing argument 3 of 'execve' from incompatible pointer type
> execve (exec_file, exec_argv, exec_env);
> ^
> In file included from /usr/local/src/mxe/usr/i686-pc-mingw32.static/include/unistd.h:13:0,
> from ../lib/unistd.h:40,
> from posix.c:50:
> /usr/local/src/mxe/usr/i686-pc-mingw32.static/include/process.h:119:42: note: expected 'const char * const*' but argument is of type 'char **'
> _CRTIMP intptr_t __cdecl __MINGW_NOTHROW execve (const char*, const char* const*, const char* const*);
>
I wouldn't worry much about these: exec() takes const so it won't change
the content, you pass on non-const so you potentially don't care whether
it changes the content. At the end, if exec() doesn't fail, it won't
even matter anymore as exec() won't return. The only case where it would
matter if exec() failed and returned and you'd want to do something with
the args; but even that would matter only in the other direction when you
had a const arg that shouldn't be changed and exec() would take
non-const and change it.
You can suppress these warnings with an explicit cast of the argument.
Regards,
Igor2
- Raw text -