Ticket #100 (closed defect: fixed)

Opened 2 years ago

Last modified 18 months ago

[PATCH] - cast of 32 bit value to 64 bit, pthread_exit

Reported by: rogueresearch Owned by: hjelmn
Milestone: Component: libusb-1.0
Keywords: Cc:
Blocked By: Blocks:

Description

Attached patch fixes a warning on darwin:

IOReturn kresult;
...
pthread_exit ((void *)kresult);

That's rather evil. :) IOReturn is a 32bit int. On x86_64, casting it to a (64 bit) pointer is not sound.

In any case, pthread_join never uses the value.

Patch is simple, and attached.

Attachments

0003-fixed-ticket-100-compiler-warning-casting-int-to-poi.patch (1.4 KB) - added by rogueresearch 2 years ago.

Download all attachments as: .zip

Change History

comment:1 Changed 2 years ago by rogueresearch

  • Summary changed from PATCH - cast of 32 bit value to 64 bit, pthread_exit to [PATCH] - cast of 32 bit value to 64 bit, pthread_exit

comment:2 Changed 2 years ago by segher

What is the warning message?

comment:3 Changed 2 years ago by rogueresearch

Tim, the language may specify the behaviour, but I maintain that it's a horrible code smell.

segher, the warning is: "warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]"

comment:4 Changed 2 years ago by segher

Ah yes. GCC has this exact same warning, and it's included in -Wall.

Using void* in this way is a common idiom; it works fine on pretty
much all compilers, but it is not portable C (it is implementation-
defined behaviour).

comment:5 Changed 2 years ago by rogueresearch

So we agree the current usage is not portable, and since pthread_join() plainly never uses the value in this case anyway, do we agree the patch is good?

Can it be accepted and merged? Thanks.

comment:6 Changed 21 months ago by rogueresearch

In [1b52e6f1a14b5a8f4b735c163e57fdc586b1e232/libusb-pbatard]:

Darwin: Fix #100 warning cast to pointer from integer of different size

comment:7 Changed 20 months ago by rogueresearch

  • Resolution set to fixed
  • Status changed from new to closed

Confirmed fixed in http://git.libusb.org/libusb.git "testing" branch.

comment:8 Changed 18 months ago by rogueresearch

In [5d0526af1a922afab02cdbdf4bb7078702759571/libusb]:

Darwin: Fix #100 warning cast to pointer from integer of different size

Note: See TracTickets for help on using tickets.