[Pkg-zsh-devel] Pointer trouble on 64-bit architectures due to implicit function declaration?

Daniel Shahaf d.s at daniel.shahaf.name
Tue Mar 1 21:37:38 UTC 2016


[ Summary at the end. ]

Axel Beckert wrote on Sun, Feb 21, 2016 at 17:25:00 +0100:
> It looks like this on amd64 for zsh 5.2-3:
> 
> % fgrep -3 "Src/Modules/termcap.c:133" ../zsh_5.2-3_amd64.build
> gcc -c -I. -I../../Src -I../../../Src -I../../../Src/Zle -I../../../Src/Modules -Wdate-time -D_FORTIFY_SOURCE=2  -DHAVE_CONFIG_H -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall -g  -o stat.o ../../../Src/Modules/stat.c
> gcc -c -I. -I../../Src -I../../../Src -I../../../Src/Zle -I../../../Src/Modules -Wdate-time -D_FORTIFY_SOURCE=2  -DHAVE_CONFIG_H -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wall -g  -o termcap.o ../../../Src/Modules/termcap.c
> ../../../Src/Modules/termcap.c: In function 'bin_echotc':
> ../../../Src/Modules/termcap.c:133:8: warning: implicit declaration of function 'tgoto' [-Wimplicit-function-declaration]
>   tputs(tgoto(t, num, atoi(*argv)), 1, putraw);
>         ^

In my normal (non-package) build, that function is declared:

    % cd Src/Modules
    % touch termcap.c && make -n
    ⋮
    gcc -c -I. -I../../Src -I../../Src -I../../Src/Zle -I.  -DHAVE_CONFIG_H -DMODULE -Wall -Wmissing-prototypes -ggdb -fPIC -o termcap..o termcap.c | fgrep -w tgoto
    ⋮
    % gcc -E -I. -I../../Src -I../../Src -I../../Src/Zle -I.  -DHAVE_CONFIG_H -DMODULE -Wall -Wmissing-prototypes -ggdb -fPIC -o - termcap.c | fgrep -w tgoto
    extern char * tgoto (const char *, int, int);
     tputs(tgoto(t, num, atoi(*argv)), 1, putraw);
    % gcc -E -I. -I../../Src -I../../Src -I../../Src/Zle -I.  -DHAVE_CONFIG_H -DMODULE -Wall -Wmissing-prototypes -ggdb -fPIC -o - termcap.c | fgrep -w tputs
    extern int tputs (const char *, int, int (*)(int));
     tputs(t, 1, putraw);
     tputs(tgoto(t, num, atoi(*argv)), 1, putraw);

>From my config.log:

    configure:9319: checking if tgoto prototype is missing
    configure:9343: result: no

... and note that, when the prototype is missing, configure arranges
for a fallback declaration of 'tgoto' to be provided (by defining
TGOTO_PROTO_MISSING, which Src/prototypes.h looks for).
Src/prototypes.h also has a similar facility for 'tputs'.

That's on stable, configured as

    Util/preconfig && ./configure --enable-zsh-debug --with-term-lib=ncursesw --prefix=$HOME/prefix/zsh

> ../../../Src/Modules/termcap.c:133:8: warning: passing argument 1 of 'tputs' makes pointer from integer without a cast [-Wint-conversion]

The arguments of an undeclared function are assumed to be ints, so
making the declarations visible ought to fix these warnings as well.

>

So, in summary:

1. The int warning is fallout of the missing declaration.

2. The missing declaration should be fixed.  (In fact, it'd be entirely
reasonable to make -Wimplicit-function-declaration a fatal error.)

Unfortunately, that's as far as I've got; I haven't looked into why the
declaration is missing in the package build (both the one provided by
the system headers and the fallback one provided by Src/prototypes.h).

Sorry for the late reply.

Daniel

P.S. The only warning in my build is:

    utils.o: In function `gettempname':
    /home/daniel/src/zsh/Src/utils.c:2146: warning: the use of `mktemp' is dangerous, better use `mkstemp' or `mkdtemp'



More information about the Pkg-zsh-devel mailing list