Skip to content

BUG: Stop casting away const in fslio and cifti - #117

Open
hjmjohnson wants to merge 1 commit into
masterfrom
pr/fix-cast-qual
Open

hjmjohnson wants to merge 1 commit into
masterfrom
pr/fix-cast-qual

Conversation

@hjmjohnson

Copy link
Copy Markdown
Member

Re-submission of #45, reverted from master on 2026-09-24 so it can be
reviewed before merging. Content is unchanged from the original.

Base: master. Independent: nothing has to land before it.

Commits
  • BUG: Stop casting away const in fslio and cifti

Ordering for all the re-submitted work is tracked in #84.

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants