Fix a long-standing typo in hts_lrand48.#1171
Conversation
|
Okay, this was not completely trivial as it turns out 😄 Fortunately no true ABI implications either as it's not the header file that was wrong. At worst it's a bug fix in the results of a mostly unused function. At least on the common platforms, by luck on return from
Currently never used in htslib/samtools/bcftools. It may be in use by other third-party code. |
|
I'd already done some basic github searches and it turns up absolutely nowhere. I suspect it really is 100% unused. Edit: also interpretting a double as a long and getting gibberish back is somewhat harmless for a random number generator. lol |
Oh I see what you mean. The usual implementation would be call lrand48 (result in rax) and then migrate that to double via something like "cvtsi2sdq %rax, %xmm0". The calling function with the proper declaration assumes it's long and just reads %rax anyway. That works, but it's compiler specific and fails with clang optimisations. Eg: Comically non-random! (I'm guessing that's the loop counter.) I still just view this as a bug fix and not an ABI change. The ABI is 100% the same, but our random number generator is now more random. (Edit: kind of... API the same. ABI compatible although the return registers may hold different values.) |
The return type of the definition was wrong, causing callers using the function to get incorrect results in some cases, mainly depending on the platform and compiler options used. Note: this function is not used by htslib. It was only added for reasons of completeness when we were putting in hts_drand48, used by htslib/ksort.h.
8c6ba58 to
b211b4c
Compare
|
Agreed, given the mismatch between header and definition can result in undefined behaviour this is really a bug fix. |
Note: this function is never used. It was only added for reasons of completeness when we were putting in hts_drand48, used by htslib/ksort.h.