diff --git a/nifti2/nifti2_io.c b/nifti2/nifti2_io.c index 58bc2bfb..34d47148 100644 --- a/nifti2/nifti2_io.c +++ b/nifti2/nifti2_io.c @@ -8805,8 +8805,10 @@ nifti_image *nifti_image_from_ascii( const char *str, int * bytes_read ) /* scan for opening string */ spos = 0 ; - ii = sscanf( str+spos , "%1023s%n" , lhs , &nn ) ; spos += nn ; - if( ii == 0 || strcmp(lhs,"") == 0 ) break ; /* end of input? */ + ii = sscanf( str+spos , "%1023s%n" , lhs , &nn ) ; + if( ii != 1 ) break ; /* nothing scanned: lhs and nn are unset */ + spos += nn ; + if( strcmp(lhs,"/>") == 0 ) break ; /* end of input? */ /* skip whitespace and the '=' marker */ @@ -8853,8 +8857,9 @@ nifti_image *nifti_image_from_ascii( const char *str, int * bytes_read ) memcpy(rhs,str+spos+1,nn) ; rhs[nn] = '\0' ; spos = (str[ii] == '\'') ? ii+1 : ii ; } else { - ii = sscanf( str+spos , "%1023s%n" , rhs , &nn ) ; spos += nn ; - if( ii == 0 ) break ; /* nothing found? */ + ii = sscanf( str+spos , "%1023s%n" , rhs , &nn ) ; + if( ii != 1 ) break ; /* nothing found: rhs and nn are unset */ + spos += nn ; } unescape_string(rhs) ; /* remove any XML escape sequences */ diff --git a/niftilib/nifti1_io.c b/niftilib/nifti1_io.c index 3d6f8fd0..a6178d27 100644 --- a/niftilib/nifti1_io.c +++ b/niftilib/nifti1_io.c @@ -6663,8 +6663,10 @@ nifti_image *nifti_image_from_ascii( const char *str, int * bytes_read ) /* scan for opening string */ spos = 0 ; - ii = sscanf( str+spos , "%1023s%n" , lhs , &nn ) ; spos += nn ; - if( ii == 0 || strcmp(lhs,"") == 0 ) break ; /* end of input? */ + ii = sscanf( str+spos , "%1023s%n" , lhs , &nn ) ; + if( ii != 1 ) break ; /* nothing scanned: lhs and nn are unset */ + spos += nn ; + if( strcmp(lhs,"/>") == 0 ) break ; /* end of input? */ /* skip whitespace and the '=' marker */ @@ -6711,8 +6715,9 @@ nifti_image *nifti_image_from_ascii( const char *str, int * bytes_read ) memcpy(rhs,str+spos+1,nn) ; rhs[nn] = '\0' ; spos = (str[ii] == '\'') ? ii+1 : ii ; } else { - ii = sscanf( str+spos , "%1023s%n" , rhs , &nn ) ; spos += nn ; - if( ii == 0 ) break ; /* nothing found? */ + ii = sscanf( str+spos , "%1023s%n" , rhs , &nn ) ; + if( ii != 1 ) break ; /* nothing found: rhs and nn are unset */ + spos += nn ; } unescape_string(rhs) ; /* remove any XML escape sequences */