xant / libhl

Simple and fast C library implementing a thread-safe API to manage hash-tables, linked lists, lock-free ring buffers and queues
GNU Lesser General Public License v3.0
420 stars 117 forks source link

Fix warning about abs() on unsigned value. #5

Closed dgryski closed 9 years ago

dgryski commented 9 years ago

via clang:

src/linklist.c:393:32: error: taking the absolute value of unsigned type 'unsigned int' has no effect [-Werror,-Wabsolute-value] src/linklist.c:393:32: note: remove the call to 'abs' since unsigned values cannot be negative

dgryski commented 9 years ago

Further discussion: The call to abs() was correct, but we were relying on an implicit cast from uint32->int and the associated integer underflow. Keep the abs() call, but document what we're doing and make the cast explicity.