Ensure indirect function calls have the correct type.#1994
Open
daviesrob wants to merge 1 commit intosamtools:developfrom
Open
Ensure indirect function calls have the correct type.#1994daviesrob wants to merge 1 commit intosamtools:developfrom
daviesrob wants to merge 1 commit intosamtools:developfrom
Conversation
Some HTSlib interfaces (notably kgetline(), kgetline2(), hts_itr_querys() and hts_parse_region()) have function callbacks that are intended to be generic, so the function signatures include a `void *` for data to be passed in. E.g. for kgetline() this would be the FILE * or hFILE * to read. Historically they have often been called with a function that has an explicit type (e.g. FILE * for fgets() used with kgetline) on the assumption that casting it to void * is harmless. Unfortunately doing this is strictly undefined behaviour and will fail in some conditions - for example if compiling with control flow integrity turned on. Recent versions of clang will also call this out when using undefined behaviour sanitizer. The solution is to create wrapper functions that do take a void *, and call the intended function with suitable casts. Some new interfaces are also added so that the messy implementation details can be hidden away, and the inputs can be better type checked. Hopefully this should also allow the wrapper functions to be inlined away. * hget_kstr() to read lines from an hFILE * to a kstring. * kgetline() to read lines from a FILE * to a kstring. * tbx_itr_querys1() to create a tabix iterator on a region. Used to reimplement the existing tbx_itr_querys() macro. * bcf_itr_querys1() to create a region iterator an a bcf file Used to reimplement the existing bcf_itr_querys() macro.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some HTSlib interfaces (notably
kgetline(),kgetline2(),hts_itr_querys()andhts_parse_region()) have function callbacks that are intended to be generic, so the function signatures include avoid *for data to be passed in. E.g. forkgetline()this would be theFILE *orhFILE *to read. Historically they have often been called with a function that has an explicit type (e.g.FILE *forfgets()used withkgetline) on the assumption that casting it tovoid *is harmless. Unfortunately doing this is strictly undefined behaviour and will fail in some conditions - for example if compiling with control flow integrity turned on. Recent versions of clang will also call this out when using undefined behaviour sanitizer. The solution is to create wrapper functions that do take avoid *, and call the intended function with suitable casts.Some new interfaces are also added so that the messy implementation details can be hidden away, and the inputs can be better type checked. Hopefully this should also allow the wrapper functions to be inlined away.
hget_kstr()to read lines from anhFILE *to akstring.kgetline()to read lines from aFILE *to akstring.tbx_itr_querys1()to create a tabix iterator on a region. Used to reimplement the existingtbx_itr_querys()macro.bcf_itr_querys1()to create a region iterator an a bcf file Used to reimplement the existingbcf_itr_querys()macro.