New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-analyzer: warnings from scan-build: uninitialized values, null pointer deref, dead store, memory leak #221

Open
pabs3 opened this Issue Dec 10, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@pabs3
Copy link
Contributor

pabs3 commented Dec 10, 2018

I built the latest git using scan-build from LLVM 8 from Debian and got some warnings about an uninitialized value a potential null pointer deref, a dead store and a potential memory leak (see below):

It would be great if you could regularly run scan-build and fix any issues before pushing new commits.

https://clang-analyzer.llvm.org/scan-build.html

$ scan-build-8 make -j4
scan-build: Using '/usr/lib/llvm-8/bin/clang' for static analysis
/usr/share/clang/scan-build-8/bin/../libexec/ccc-analyzer -fPIC -O2 -g -pipe -Wall -std=c99 -DDISCORD_PLUGIN_VERSION='"0.9.2018.12.10.git.14bc817"' -DMARKDOWN_PIDGIN -DENABLE_NLS -DLOCALEDIR=\"/usr/share/locale\"  -shared -o libdiscord.so libdiscord.c markdown.c -Wl,-z,relro `pkg-config purple glib-2.0 json-glib-1.0 --libs --cflags`   -Ipurple2compat -g -ggdb
libdiscord.c: In function ‘discord_inflate.isra.16’:
libdiscord.c:3477:20: warning: ‘gzres’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  if (gzres != Z_OK && gzres != Z_STREAM_END) {
                    ^
libdiscord.c:3477:12: warning: The left operand of '!=' is a garbage value
        if (gzres != Z_OK && gzres != Z_STREAM_END) {
            ~~~~~ ^
libdiscord.c:3866:118: warning: Access to field 'id' results in a dereference of a null pointer (loaded from variable 'guild')
        gchar *url = g_strdup_printf("https://" DISCORD_API_SERVER "/api/v6/guilds/%" G_GUINT64_FORMAT "/members/@me/nick", guild->id);
                                                                                                                            ^~~~~~~~~
libdiscord.c:4245:3: warning: Value stored to 'name' is never read
                name = channel->name;
                ^      ~~~~~~~~~~~~~
libdiscord.c:4658:3: warning: Potential leak of memory pointed to by 'msg'
                purple_conversation_present_error(who, da->account, _("Cannot send a message to someone who is not on your friend list."));
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./purple_compat.h:63:43: note: expanded from macro 'purple_conversation_present_error'
#define purple_conversation_present_error purple_conv_present_error
                                          ^~~~~~~~~~~~~~~~~~~~~~~~~
4 warnings generated.
scan-build: 4 bugs found.
scan-build: Run 'scan-view /tmp/user/1000/scan-build-2018-12-10-160544-8678-1' to examine bug reports.

EionRobb added a commit that referenced this issue Dec 10, 2018

@EionRobb

This comment has been minimized.

Copy link
Owner

EionRobb commented Dec 10, 2018

After issue #220 I was running it through pvs-studio and found a few more potential issues :)

@pabs3

This comment has been minimized.

Copy link
Contributor

pabs3 commented Dec 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment