BUG: Stop casting away const in fslio and cifti - #117
Open
hjmjohnson wants to merge 1 commit into
Open
hjmjohnson wants to merge 1 commit into
hjmjohnson wants to merge 1 commit into
Conversation
Nine -Wcast-qual warnings. Casting away const is how a read-only
contract turns into a write to memory the caller thought was safe, so
each was looked at rather than silenced.
fslio.c, FslGetFileType2()
mutablefslio = (FSLIO *)fslio; /* dodgy and will generate warnings */
mutablefslio->niftiptr->nifti_type = ...;
The comment is right that it looks dodgy, but the cast was never
needed. `const FSLIO * fslio` makes the *member* niftiptr const --
its type is `nifti_image * const` -- while what it points at stays
fully mutable. The assignment is legal as written, so the cast and
the local both go.
fslio.c FslWriteVolumes(), cifti axio_num_tokens(), text_to_i64(),
text_to_f64()
Pointers cast to char * and then only read: walked, indexed, or
handed to strtoll()/strtod(), which take const char *. Declared
const, casts removed.
cifti strip_whitespace()
Returned `(char *)str` on its early-exit paths, handing the caller a
writable pointer to the const string it passed in. The function is
static, so its return type is nobody else's business; it now returns
const char *.
(cherry picked from commit 0a9aa9c)
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.
Re-submission of #45, reverted from
masteron 2026-09-24 so it can bereviewed before merging. Content is unchanged from the original.
Base:
master. Independent: nothing has to land before it.Commits
Ordering for all the re-submitted work is tracked in #84.