From: Brian S. <xue...@us...> - 2007-10-05 18:39:22
|
Update of /cvsroot/popfile/windows/add-ons In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11297/add-ons Modified Files: Tag: b0_22_2 OnDemand.nsi Log Message: Where appropriate, make string processing loops more robust by using the string length to test for end-of-string instead of assuming a null character marks the end of the string. Index: OnDemand.nsi =================================================================== RCS file: /cvsroot/popfile/windows/add-ons/Attic/OnDemand.nsi,v retrieving revision 1.1.2.2 retrieving revision 1.1.2.3 diff -C2 -d -r1.1.2.2 -r1.1.2.3 *** OnDemand.nsi 21 Sep 2007 01:04:10 -0000 1.1.2.2 --- OnDemand.nsi 5 Oct 2007 18:39:24 -0000 1.1.2.3 *************** *** 930,975 **** Function StrCheckDecimal ! !define DECIMAL_DIGIT "0123456789" ; accept only these digits ! !define BAD_OFFSET 10 ; length of DECIMAL_DIGIT string ! Exch $0 ; The input string ! Push $1 ; Holds the result: either "" (if input is invalid) or the input string (if valid) ! Push $2 ; A character from the input string ! Push $3 ; The offset to a character in the "validity check" string ! Push $4 ; A character from the "validity check" string ! Push $5 ; Holds the current "validity check" string ! StrCpy $1 "" next_input_char: ! StrCpy $2 $0 1 ; Get the next character from the input string ! StrCmp $2 "" done ! StrCpy $5 ${DECIMAL_DIGIT}$2 ; Add it to end of "validity check" to guarantee a match ! StrCpy $0 $0 "" 1 ! StrCpy $3 -1 next_valid_char: ! IntOp $3 $3 + 1 ! StrCpy $4 $5 1 $3 ; Extract next "valid" char (from "validity check" string) ! StrCmp $2 $4 0 next_valid_char ! IntCmp $3 ${BAD_OFFSET} invalid 0 invalid ; If match is with the char we added, input is bad ! StrCpy $1 $1$4 ; Add "valid" character to the result goto next_input_char invalid: ! StrCpy $1 "" done: ! StrCpy $0 $1 ; Result is either a string of decimal digits or "" ! Pop $5 ! Pop $4 ! Pop $3 ! Pop $2 ! Pop $1 ! Exch $0 ; place result on top of the stack !undef DECIMAL_DIGIT !undef BAD_OFFSET FunctionEnd --- 930,994 ---- Function StrCheckDecimal ! !define DECIMAL_DIGIT "0123456789" ; accept only these digits ! !define BAD_OFFSET 10 ; length of DECIMAL_DIGIT string ! !define L_STRING $0 ; The input string ! !define L_RESULT $1 ; Holds the result: either "" (if input is invalid) or the input string (if valid) ! !define L_CURRENT $2 ; A character from the input string ! !define L_OFFSET $3 ; The offset to a character in the "validity check" string ! !define L_VALIDCHAR $4 ; A character from the "validity check" string ! !define L_VALIDLIST $5 ; Holds the current "validity check" string ! !define L_CHARSLEFT $6 ; To cater for MBCS input strings, terminate when end of string reached, not when a null byte reached ! Exch ${L_STRING} ! Push ${L_RESULT} ! Push ${L_CURRENT} ! Push ${L_OFFSET} ! Push ${L_VALIDCHAR} ! Push ${L_VALIDLIST} ! Push ${L_CHARSLEFT} ! ! StrCpy ${L_RESULT} "" next_input_char: ! StrLen ${L_CHARSLEFT} ${L_STRING} ! StrCmp ${L_CHARSLEFT} 0 done ! StrCpy ${L_CURRENT} ${L_STRING} 1 ; Get the next character from the input string ! StrCpy ${L_VALIDLIST} ${DECIMAL_DIGIT}${L_CURRENT} ; Add it to end of "validity check" to guarantee a match ! StrCpy ${L_STRING} ${L_STRING} "" 1 ! StrCpy ${L_OFFSET} -1 next_valid_char: ! IntOp ${L_OFFSET} ${L_OFFSET} + 1 ! StrCpy ${L_VALIDCHAR} ${L_VALIDLIST} 1 ${L_OFFSET} ; Extract next "valid" char (from "validity check" string) ! StrCmp ${L_CURRENT} ${L_VALIDCHAR} 0 next_valid_char ! IntCmp ${L_OFFSET} ${BAD_OFFSET} invalid 0 invalid ; If match is with the char we added, input is bad ! StrCpy ${L_RESULT} ${L_RESULT}${L_VALIDCHAR} ; Add "valid" character to the result goto next_input_char invalid: ! StrCpy ${L_RESULT} "" done: ! StrCpy ${L_STRING} ${L_RESULT} ; Result is either a string of decimal digits or "" ! Pop ${L_CHARSLEFT} ! Pop ${L_VALIDLIST} ! Pop ${L_VALIDCHAR} ! Pop ${L_OFFSET} ! Pop ${L_CURRENT} ! Pop ${L_RESULT} ! Exch ${L_STRING} ; Place result on top of the stack !undef DECIMAL_DIGIT !undef BAD_OFFSET + !undef L_STRING + !undef L_RESULT + !undef L_CURRENT + !undef L_OFFSET + !undef L_VALIDCHAR + !undef L_VALIDLIST + !undef L_CHARSLEFT + FunctionEnd |