AFNI Message Board

Dear AFNI users-

We are very pleased to announce that the new AFNI Message Board framework is up! Please join us at:

https://discuss.afni.nimh.nih.gov

Existing user accounts have been migrated, so returning users can login by requesting a password reset. New users can create accounts, as well, through a standard account creation process. Please note that these setup emails might initially go to spam folders (esp. for NIH users!), so please check those locations in the beginning.

The current Message Board discussion threads have been migrated to the new framework. The current Message Board will remain visible, but read-only, for a little while.

Sincerely, AFNI HQ

History of AFNI updates  

|
May 28, 2009 02:57PM
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
Subject Author Posted

Bug in strblast

Randy Notestine May 28, 2009 02:57PM

Re: Bug in strblast

rick reynolds May 28, 2009 06:02PM