BUG: Do not write to the stream that failed to open - #72
Conversation
ec9255c to
65c3610
Compare
65c3610 to
ff5dd86
Compare
ff5dd86 to
a46d8f4
Compare
|
Rebased onto current Worth your call: Rebase and commit-message cleanupThe ~29 shared-base commits are already on Message cleanup: removed the Test added, and the red proof
Red, with only the Green with the fix. The script asserts a normal exit and the presence of the diagnostic, not merely that the command failed. Companion assertion: an openable Scope note: the red proof covers the |
a46d8f4 to
162e8dc
Compare
open_write_stream() returns NULL when its fopen() fails, and reports it. Both callers then used the result without testing it. $ cifti_tool -input c.nii -disp_cext -output /nonexistent-dir/x.txt ** failed to open '/nonexistent-dir/x.txt' for writing Segmentation fault (core dumped) disp_cifti_extension() passes it to fprintf(). eval_cifti_extension() hands it to axml_set_wstream(), so the NULL becomes the xml library's write stream and every later write follows it. Both now return 1; the message has already been printed. This file is behind USE_CIFTI_CODE, which defaults to OFF, so the standard workflows do not compile it. Verified with -DUSE_CIFTI_CODE=ON.
Driven through a cmake -P script rather than add_test, because PASS_REGULAR_EXPRESSION ignores the exit status and a crash that had already printed the diagnostic would pass. The script pins that the tool exits normally and reports the failure, and that an openable -output is still written with the extension in it, so refusing every write would not pass.
162e8dc to
812fbb1
Compare
5c08eb3
into
InsightSoftwareConsortium:master
open_write_stream()returns NULL when itsfopen()fails, and reports it. Both callers then used the result without testing it.disp_cifti_extension()passes it tofprintf().eval_cifti_extension()hands it toaxml_set_wstream(), so the NULL becomes the XML library's write stream and every later write follows it. Both now return 1 — the message has already been printed.Split out of #56, which is about a different defect in one of the same functions (an extension search that never advanced). #56 touches adjacent lines, so if both are in flight, merge #56 first and this rebases.
Note
cifti/is behindUSE_CIFTI_CODE, which defaults to OFF, so the standard workflows do not compile this file. Verified locally with-DUSE_CIFTI_CODE=ON.🤖 Generated with Claude Code