Skip to content

Defining NDEBUG breaks the build #38

@jaskij

Description

@jaskij

While working on #37 any sort of release build was segfaulting. After some investigation I found out that the reason for this is that CMake defaults to defining NDEBUG in release builds. Looking at

assert(pthread_create(&threads[thread], NULL, thread_function, (void *)(thhandle->targs[thread])) == 0);
it becomes obvious that disabling asserts would not create the threads, and the later pthread_join segfaults.

A possible fix, which I confirmed to work, is:

diff --git a/helsing/src/main.c b/helsing/src/main.c
index f0028c6..4ee5bba 100644
--- a/helsing/src/main.c
+++ b/helsing/src/main.c
@@ -61,8 +61,10 @@ int main(int argc, char *argv[])
 			continue;
 
 		fprintf(stderr, "Checking interval: [%llu, %llu]\n", lmin, lmax);
-		for (thread_t thread = 0; thread < options.threads; thread++)
-			assert(pthread_create(&threads[thread], NULL, thread_function, (void *)(thhandle->targs[thread])) == 0);
+		for (thread_t thread = 0; thread < options.threads; thread++) {
+			int pthread_create_return = pthread_create(&threads[thread], NULL, thread_function, (void*) (thhandle->targs[thread]));
+			assert(pthread_create_return == 0);
+		}
 		for (thread_t thread = 0; thread < options.threads; thread++)
 			pthread_join(threads[thread], 0);
 	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions