AFNI's strblast program occasionally fails to locate occurrences of the target string.
Example of bug:
- Create a one line text file, Test.txt, containing: "Kirk, Klingon"
- Run the following command: strblast -new_string Captain Klingon Test.txt
++ Found no copies of target Klingon in file Test.txt
Description of bug:
Following are lines 127-142 from strblast.c:
127 /* scan for start character */
128
129 for( nfind=ii=0 ; ii < nbuf-ntarg ; ii++ ){
130
131 if( fbuf[ii] == targ[0] ){ /* if find it, check rest of string */
132
133 for( jj=1; jj < ntarg && fbuf[ii+jj]==targ[jj] ; jj++ ) ; /* nada */
134
135 if( jj == ntarg ){ /* found it */
136 nfind++ ;
137 for( jj=0 ; jj < njstr ; jj++ ) fbuf[ii+jj] = jstr[jj] ;
138 for( ; jj < ntarg ; jj++ ) fbuf[ii+jj] = newchar ;
139 }
140 ii += ntarg-1 ;
141 }
142 }
At line 140, ii is incremented by ntarg-1, regardless of whether a complete match of the target was found or not. So in the above example, after matching the "K" in Kirk with the "K" in Klingon, but failing to match additional characters in the target, ii is incremented past the "K" in Klingon.
Proposed fix:
I believe the best fix would be to move line 140 within the if structure currently spanning lines 135 to 139 (the "/* found it */" structure), so that ii is only incremented if a complete match has been found. I believe that this will guarantee that all occurrences of target are found. (A different approach would be to change line 140 to "ii += jj-1", but I do not believe that this would guarantee that all occurrences of target are found.)
- Randy
--
Randy Notestine
Senior Software Engineer
Laboratory of Cognitive Imaging (LOCI)
UCSD Dept. of Psychiatry