[Mrtrix-discussion] PATCH: fix writing to gzipped nifti when already exists

Chris Adamson chris.adamson at mcri.edu.au
Thu May 1 22:44:02 PDT 2014


I found a serious bug when mrview overwrites an ROI image that is in nii gz format it crashes. This is a patch:

diff -ru b/lib/image/mapper.cpp a/lib/image/mapper.cpp
--- b/lib/image/mapper.cpp        2014-02-25 20:49:26.000000000 +1100
+++ a/lib/image/mapper.cpp     2014-05-02 15:37:46.547683468 +1000
@@ -210,6 +210,13 @@
       info ("writing compressed data to \"" +  gzfile + "\"...");
+      // check if file exists,
+      if(g_file_test (gzfile.c_str(), G_FILE_TEST_EXISTS)) {
+        if(g_unlink(gzfile.c_str()) == -1) {
+           fclose (infile);
+           throw Exception ("error deleting file \"" + gzfile + "\": " + Glib::strerror(errno));
+        }
+      }
       int fid = g_open (gzfile.c_str(), O_CREAT | O_RDWR | O_EXCL, 0755);
       if (fid < 0) {
         fclose (infile);

Dr Chris Adamson
Research Officer, Developmental Imaging, Murdoch Childrens Research Institute
Murdoch Childrens Research Institute
Royal Children's Hospital
Flemington Road, Parkville, Victoria  3052, Australia
www.mcri.edu.au<http://www.mcri.edu.au/>
E   chris.adamson at mcri.edu.au
T   03 9936 6780


______________________________________________________________________
This email has been scanned by the Symantec Email Security.cloud service.
For more information please visit http://www.symanteccloud.com
______________________________________________________________________
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.nitrc.org/pipermail/mrtrix-discussion/attachments/20140502/9ece1929/attachment.html>


More information about the Mrtrix-discussion mailing list