|
From: Rene-Paul D. <ren...@ch...> - 2017-07-12 21:48:56
|
Hello,
I found what i think is a bug in the /_nrrdFormatNRRD_write() /function
in formatNrrd.c.
As i can't subscribe to sourceforge (/Your registration violated our
antispam filter/ [sic]) I 'm posting it here
Description:
the 'data file' field is not always the last one especially in the case
of 'data file: LIST', When the nrrd file format specs says:
/data file: LIST [<//subdim//>//]: /There are multiple detached data
files, and their filenames are given explicitly, in the NRRD header,
one filename per line, in the line starting after data file field
specification, until the end of file. Thus, this form of the field
specification *must* be the last specification of the header.
Step to reproduce the bug:
/unu make -h -i A.nrrd B.nrrd -t "unsigned int" -s 4 4 4 2 -kv
foo:=bar /
gives:
/NRRD0004//
//# Complete NRRD file format specification at://
//# http://teem.sourceforge.net/nrrd/format.html//
//type: unsigned int//
//dimension: 4//
//sizes: 4 4 4 2//
//endian: little//
//encoding: raw//
//data file: LIST//
//A.nrrd//
//B.nrrd//
//foo:=bar/
An easy quick patch is attached to the mail:
Index: src/nrrd/formatNRRD.c
===================================================================
--- src/nrrd/formatNRRD.c (revision 6307)
+++ src/nrrd/formatNRRD.c (working copy)
@@ -703,7 +703,7 @@
}
/* this is where the majority of the header printing happens */
- for (ii=1; ii<=NRRD_FIELD_MAX; ii++) {
+ for (ii=1; ii<NRRD_FIELD_MAX; ii++) {
if (_nrrdFieldInteresting(nrrd, nio, ii)) {
if (file) {
_nrrdFprintFieldInfo(file, "", nrrd, nio, ii, AIR_FALSE);
@@ -770,6 +770,29 @@
}
}
+ /* always finish by data file field in case of LIST */
+ if (_nrrdFieldInteresting(nrrd, nio, ii)) {
+ if (file) {
+ _nrrdFprintFieldInfo(file, "", nrrd, nio, ii, AIR_FALSE);
+ } else if (nio->headerStringWrite) {
+ _nrrdSprintFieldInfo(&strptr, "", nrrd, nio, ii, AIR_FALSE);
+ if (strptr) {
+ strcat(nio->headerStringWrite, strptr);
+ strcat(nio->headerStringWrite, "\n");
+ free(strptr);
+ strptr = NULL;
+ }
+ } else {
+ _nrrdSprintFieldInfo(&strptr, "", nrrd, nio, ii, AIR_FALSE);
+ if (strptr) {
+ nio->headerStrlen += AIR_CAST(unsigned int, strlen(strptr));
+ nio->headerStrlen += AIR_CAST(unsigned int, strlen("\n"));
+ free(strptr);
+ strptr = NULL;
+ }
+ }
+ }
+
if (file) {
if (!( nio->detachedHeader || _nrrdDataFNNumber(nio) > 1 )) {
fprintf(file, "\n");
Regards.
Rene-Paul Debroize
|