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

incorrect pointer tested against NULL #3683

Closed
Banzai24-yht opened this issue Jun 20, 2023 · 1 comment
Closed

incorrect pointer tested against NULL #3683

Banzai24-yht opened this issue Jun 20, 2023 · 1 comment
Assignees

Comments

@Banzai24-yht
Copy link

using cppcheck on the source code :

lib/common/threading.c:79:6: warning: Either the condition '!thread' is redundant or there is possible null pointer dereference: thread. [nullPointerRedundantCheck]
    *thread = NULL;
     ^
lib/common/threading.c:94:9: note: Assuming that condition '!thread' is not redundant
    if (!thread) {
        ^
lib/common/threading.c:79:6: note: Null pointer dereference
    *thread = NULL;
     ^
lib/common/threading.c:93:6: warning: Either the condition '!thread' is redundant or there is possible null pointer dereference: thread. [nullPointerRedundantCheck]
    *thread = (HANDLE)_beginthreadex(NULL, 0, worker, &thread_param, 0, NULL);
     ^
lib/common/threading.c:94:9: note: Assuming that condition '!thread' is not redundant
    if (!thread) {
        ^
lib/common/threading.c:93:6: note: Null pointer dereference
    *thread = (HANDLE)_beginthreadex(NULL, 0, worker, &thread_param, 0, NULL);
     ^

I think the correction may be :

diff --git a/lib/common/threading.c b/lib/common/threading.c
index ca155b9b..ba76e613 100644
--- a/lib/common/threading.c
+++ b/lib/common/threading.c
@@ -91,7 +91,7 @@ int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,

     /* Spawn thread */
     *thread = (HANDLE)_beginthreadex(NULL, 0, worker, &thread_param, 0, NULL);
-    if (!thread) {
+    if (!*thread) {
         ZSTD_pthread_mutex_destroy(&thread_param.initialized_mutex);
         ZSTD_pthread_cond_destroy(&thread_param.initialized_cond);
         return errno;


@Cyan4973
Copy link
Contributor

Indeed, I think the analysis is correct.
To be fixed

@Cyan4973 Cyan4973 self-assigned this Jun 20, 2023
Cyan4973 added a commit that referenced this issue Jun 20, 2023
gcflymoto pushed a commit to gcflymoto/zstd that referenced this issue Jun 21, 2023
hswong3i pushed a commit to alvistack/facebook-zstd that referenced this issue Mar 27, 2024
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

No branches or pull requests

2 participants