Skip to content
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

Fixes for issues found with cppcheck tool #4865

Closed
wants to merge 1 commit into from

Conversation

ironMann
Copy link
Contributor

The patch fixes small number of errors/false positives reported by cppcheck static analysis tool for C/C++.

List of errors:

[cmd/zfs/zfs_main.c:4444]: (error) Possible null pointer dereference: who_perm
[cmd/zfs/zfs_main.c:4445]: (error) Possible null pointer dereference: who_perm
[cmd/zfs/zfs_main.c:4446]: (error) Possible null pointer dereference: who_perm
[cmd/zpool/zpool_iter.c:317]: (error) Uninitialized variable: nvroot
[cmd/zpool/zpool_vdev.c:1526]: (error) Memory leak: child
[lib/libefi/rdwr_efi.c:1118]: (error) Memory leak: efi_label
[lib/libuutil/uu_misc.c:207]: (error) va_list 'args' was opened but not closed by va_end().
[lib/libzfs/libzfs_import.c:1554]: (error) Dangerous usage of 'diskname' (strncpy doesn't always null-terminate it).
[lib/libzfs/libzfs_sendrecv.c:3279]: (error) Dereferencing 'cp' after it is deallocated / released
[tests/zfs-tests/cmd/file_write/file_write.c:154]: (error) Possible null pointer dereference: operation
[tests/zfs-tests/cmd/randfree_file/randfree_file.c:90]: (error) Memory leak: buf

Issue #1392

@behlendorf
Copy link
Contributor

Nice! This will allow us to add a cppcheck step the to buildbot so we can keep at least keep the code cppcheck clean. This patch does miss one warning in zinject.c.

[cmd/zinject/zinject.c:1068]: (error) Uninitialized variable: dataset

@ironMann
Copy link
Contributor Author

I see, it might be cppcheck version (Cppcheck 1.67). I'll try compiling from source.

@behlendorf
Copy link
Contributor

I was running with cppcheck 1.72.

@ironMann
Copy link
Contributor Author

ironMann commented Jul 19, 2016

Ok, I just tried latest v1.74, and it gives two additional hits:

[lib/libnvpair/libnvpair.c:395]: (error) va_list 'ap' was opened but not closed by va_end().
[module/nvpair/nvpair.c:1547]: (error) va_list 'ap' was opened but not closed by va_end().

Both of these seem wrong. As if var arg analysis is confused by switch statement somehow.

char pool[MAXNAMELEN];
char dataset[MAXNAMELEN];
char pool[MAXNAMELEN] = { 0 };
char dataset[MAXNAMELEN] = { 0 };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

= ""

The patch fixes small number of errors/false positives reported by `cppcheck`,
static analysis tool for C/C++.

cppcheck 1.72

$ cppcheck . --force --quiet
[cmd/zfs/zfs_main.c:4444]: (error) Possible null pointer dereference: who_perm
[cmd/zfs/zfs_main.c:4445]: (error) Possible null pointer dereference: who_perm
[cmd/zfs/zfs_main.c:4446]: (error) Possible null pointer dereference: who_perm
[cmd/zpool/zpool_iter.c:317]: (error) Uninitialized variable: nvroot
[cmd/zpool/zpool_vdev.c:1526]: (error) Memory leak: child
[lib/libefi/rdwr_efi.c:1118]: (error) Memory leak: efi_label
[lib/libuutil/uu_misc.c:207]: (error) va_list 'args' was opened but not closed by va_end().
[lib/libzfs/libzfs_import.c:1554]: (error) Dangerous usage of 'diskname' (strncpy doesn't always null-terminate it).
[lib/libzfs/libzfs_sendrecv.c:3279]: (error) Dereferencing 'cp' after it is deallocated / released
[tests/zfs-tests/cmd/file_write/file_write.c:154]: (error) Possible null pointer dereference: operation
[tests/zfs-tests/cmd/randfree_file/randfree_file.c:90]: (error) Memory leak: buf
[cmd/zinject/zinject.c:1068]: (error) Uninitialized variable: dataset

Issue openzfs#1392

Signed-off-by: Gvozden Neskovic <neskovic@gmail.com>
@behlendorf
Copy link
Contributor

Merged as:

a64f903 Fixes for issues found with cppcheck tool

@behlendorf behlendorf closed this Jul 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants