From: Khem Raj Date: Tue, 28 Jan 2020 03:50:04 +0000 (-0800) Subject: drd/tests/pth_detached3: Make pthread_detach() call portable across platforms X-Git-Tag: VALGRIND_3_16_0~106 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92fcf75d6d3903e45492b041bf4ad07787d2e58a;p=thirdparty%2Fvalgrind.git drd/tests/pth_detached3: Make pthread_detach() call portable across platforms pthread_t is opaque type therefore we can not apply simple arithmetic to variables of pthread_t type this test needs to pass a invalid pthread_t handle, typcasting to uintptr_t works too and is portable across glibc and musl Fixes | pth_detached3.c:24:25: error: invalid use of undefined type 'struct __pthread' | 24 | pthread_detach(thread + 8); | | ^ [ bvanassche: reformatted patch description and fixed up line numbers ] --- diff --git a/drd/tests/pth_detached3.c b/drd/tests/pth_detached3.c index c02eef11ab..efeb15b72d 100644 --- a/drd/tests/pth_detached3.c +++ b/drd/tests/pth_detached3.c @@ -4,6 +4,7 @@ #include #include #include +#include static void* thread_func(void* arg) { @@ -21,7 +22,7 @@ int main(int argc, char** argv) pthread_detach(thread); /* Invoke pthread_detach() with an invalid thread ID. */ - pthread_detach(thread + 8); + pthread_detach((pthread_t)((uintptr_t)thread + 8)); fprintf(stderr, "Finished.\n"); diff --git a/drd/tests/pth_detached3.stderr.exp1 b/drd/tests/pth_detached3.stderr.exp1 index 58412ec4cc..8dd58ba0f3 100644 --- a/drd/tests/pth_detached3.stderr.exp1 +++ b/drd/tests/pth_detached3.stderr.exp1 @@ -1,11 +1,11 @@ pthread_detach(): invalid thread ID 0x........ at 0x........: pthread_detach (drd_pthread_intercepts.c:?) - by 0x........: main (pth_detached3.c:21) + by 0x........: main (pth_detached3.c:22) pthread_detach(): invalid thread ID 0x........ at 0x........: pthread_detach (drd_pthread_intercepts.c:?) - by 0x........: main (pth_detached3.c:24) + by 0x........: main (pth_detached3.c:25) Finished. diff --git a/drd/tests/pth_detached3.stderr.exp2 b/drd/tests/pth_detached3.stderr.exp2 index bdc5cf8c9b..e82dee14db 100644 --- a/drd/tests/pth_detached3.stderr.exp2 +++ b/drd/tests/pth_detached3.stderr.exp2 @@ -2,12 +2,12 @@ pthread_detach(): invalid thread ID 0x........ at 0x........: vgDrd_set_joinable (drd_pthread_intercepts.c:?) by 0x........: pthread_detach (drd_pthread_intercepts.c:?) - by 0x........: main (pth_detached3.c:21) + by 0x........: main (pth_detached3.c:22) pthread_detach(): invalid thread ID 0x........ at 0x........: vgDrd_set_joinable (drd_pthread_intercepts.c:?) by 0x........: pthread_detach (drd_pthread_intercepts.c:?) - by 0x........: main (pth_detached3.c:24) + by 0x........: main (pth_detached3.c:25) Finished.