about summary refs log tree commit diff
path: root/src/misc/a64l.c
Commit message (Collapse)AuthorAgeFilesLines
* fix a64l undefined behavior on ILP32 archs, wrong results on LP64 archsRich Felker2016-05-231-3/+6
| | | | | | | | | | | | | | | | | | | the difference of pointers is a signed type ptrdiff_t; if it is only 32-bit, left-shifting it by 30 bits produces undefined behavior. cast the difference to an appropriate unsigned type, uint32_t, before shifting to avoid this. the a64l function is specified to return a signed 32-bit result in type long. as noted in the bug report by Ed Schouten, converting implicitly from uint32_t only produces the desired result when long is a 32-bit type. since the computation has to be done in unsigned arithmetic to avoid overflow, simply cast the result to int32_t. further, POSIX leaves the behavior on invalid input unspecified but not undefined, so we should not take the difference between the potentially-null result of strchr and the base pointer without first checking the result. the simplest behavior is just returning the partial conversion already performed in this case, so do that.
* implement a64l and l64a (legacy xsi stuff)Rich Felker2012-03-011-0/+26