Potential use of uniinitialized vairaible
Closed, ResolvedPublic

Description

export CC=/usr/local/bin/clang
export CXX=/usr/local/bin/clang++
export CPPFLAGS="-fsanitize=address -fsanitize=undefined"
export CFLAGS="-fsanitize=address -fsanitize=undefined"
export CFLAGS="-fsanitize=address -fsanitize=undefined -fno-sanitize=vptr"

export PREFIX=~/gpg-sanitize

LIBRARY=libksba
VERSION=1.3.2
FILE="$LIBRARY-$VERSION"

cd "$FILE"
./configure --enable-static --disable-shared
--with-libgpg-error-prefix="$PREFIX" --prefix="$PREFIX"
make

make check | /usr/local/bin/asan_symbolize.py


...
libtool: compile: /usr/local/bin/clang -DHAVE_CONFIG_H -I. -I.. -I../gl -I../gl
-fsanitize=address -fsanitize=undefined -I/home/jwalton/gpg-sanitize/include
-fsanitize=address -fsanitize=undefined -fno-sanitize=vptr -Wall -Wcast-align
-Wshadow -Wstrict-prototypes -Wpointer-arith -Wno-pointer-sign
-fvisibility=hidden -MT cert.lo -MD -MP -MF .deps/cert.Tpo -c cert.c -o cert.o
cert.c:466:7: warning: variable 'algo' is used uninitialized whenever 'if'

    condition is true [-Wsometimes-uninitialized]
if (!n || n->off == -1)
    ^~~~~~~~~~~~~~~~~~

cert.c:476:10: note: uninitialized use occurs here

return algo;
       ^~~~

cert.c:466:3: note: remove the 'if' if its condition is always false

if (!n || n->off == -1)
^~~~~~~~~~~~~~~~~~~~~~~

cert.c:466:7: warning: variable 'algo' is used uninitialized whenever '||'

    condition is true [-Wsometimes-uninitialized]
if (!n || n->off == -1)
    ^~

cert.c:476:10: note: uninitialized use occurs here

return algo;
       ^~~~

cert.c:466:7: note: remove the '||' if its condition is always false

if (!n || n->off == -1)
    ^~~~~

cert.c:442:13: note: initialize the variable 'algo' to silence this warning

char *algo;
          ^
           = NULL

2 warnings generated.

Details

Version
1.3.2
JW set Version to 1.3.2.Mar 5 2015, 10:57 PM
JW added projects: libksba, Bug Report.
JW added a subscriber: JW.
JW added a comment.Mar 6 2015, 6:16 AM

JW added a comment.Mar 6 2015, 6:16 AM

Updated cert.c which initializes the variable algo.

JW added a comment.Mar 6 2015, 6:17 AM

Changed status to 'unread'. I'm not chatting.

werner closed this task as Resolved.Mar 10 2015, 9:44 AM
werner claimed this task.
werner added a project: Mistaken.

No c+p of warnings please! Use gnupg-devel for such things.

werner reopened this task as Open.Mar 10 2015, 9:45 AM

(If you want to provide a fix, please provide a diff and not the complete file.)

werner closed this task as Resolved.Mar 10 2015, 9:45 AM