From: Brian S. <xue...@us...> - 2007-10-05 18:39:23
|
Update of /cvsroot/popfile/windows In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11297 Modified Files: Tag: b0_22_2 pfi-library.nsh stop_popfile.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: stop_popfile.nsi =================================================================== RCS file: /cvsroot/popfile/windows/stop_popfile.nsi,v retrieving revision 1.14.4.7 retrieving revision 1.14.4.8 diff -C2 -d -r1.14.4.7 -r1.14.4.8 *** stop_popfile.nsi 5 May 2007 12:28:07 -0000 1.14.4.7 --- stop_popfile.nsi 5 Oct 2007 18:39:25 -0000 1.14.4.8 *************** *** 123,127 **** Caption "POPFile Silent Shutdown Utility" ! !define C_VERSION "0.6.5" ; see 'VIProductVersion' comment below for format details !define C_OUTFILE "stop_pf.exe" --- 123,127 ---- Caption "POPFile Silent Shutdown Utility" ! !define C_VERSION "0.6.6" ; see 'VIProductVersion' comment below for format details !define C_OUTFILE "stop_pf.exe" *************** *** 259,264 **** --- 259,266 ---- ${MB_NL} ECHO Shutdown succeeded\ ${MB_NL} GOTO DONE\ + ${MB_NL}\ ${MB_NL} :FAILED\ ${MB_NL} ECHO **** Shutdown failed ****\ + ${MB_NL}\ ${MB_NL} :DONE\ ${MB_NL}${MB_NL}\ *************** *** 443,458 **** !define L_CHAR $R9 ; a character from the input list ! !define L_LIST $R8 ; input list of parameters (may be empty) ! !define L_PARAM $R7 ; the first parameter found Exch ${L_LIST} Push ${L_PARAM} Push ${L_CHAR} StrCpy ${L_PARAM} "" loop_L: StrCpy ${L_CHAR} ${L_LIST} 1 ; get next char from input list - StrCmp ${L_CHAR} "" done StrCpy ${L_LIST} ${L_LIST} "" 1 ; remove char from input list StrCmp ${L_CHAR} " " loop_L --- 445,463 ---- !define L_CHAR $R9 ; a character from the input list ! !define L_LENGTH $R8 ; use string length to determine if end-of-string reached ! !define L_LIST $R7 ; input list of parameters (may be empty) ! !define L_PARAM $R6 ; the first parameter found Exch ${L_LIST} Push ${L_PARAM} Push ${L_CHAR} + Push ${L_LENGTH} StrCpy ${L_PARAM} "" loop_L: + StrLen ${L_LENGTH} ${L_LIST} + StrCmp ${L_LENGTH} 0 done StrCpy ${L_CHAR} ${L_LIST} 1 ; get next char from input list StrCpy ${L_LIST} ${L_LIST} "" 1 ; remove char from input list StrCmp ${L_CHAR} " " loop_L *************** *** 460,471 **** loop_P: StrCpy ${L_PARAM} ${L_PARAM}${L_CHAR} StrCpy ${L_CHAR} ${L_LIST} 1 ; get next char from input list - StrCmp ${L_CHAR} "" done StrCpy ${L_LIST} ${L_LIST} "" 1 StrCmp ${L_CHAR} " " 0 loop_P ; loop until a space is found loop_T: StrCpy ${L_CHAR} ${L_LIST} 1 ; get next char from input list - StrCmp ${L_CHAR} "" done StrCmp ${L_CHAR} " " 0 done StrCpy ${L_LIST} ${L_LIST} "" 1 ; remove trailing spaces --- 465,478 ---- loop_P: StrCpy ${L_PARAM} ${L_PARAM}${L_CHAR} + StrLen ${L_LENGTH} ${L_LIST} + StrCmp ${L_LENGTH} 0 done StrCpy ${L_CHAR} ${L_LIST} 1 ; get next char from input list StrCpy ${L_LIST} ${L_LIST} "" 1 StrCmp ${L_CHAR} " " 0 loop_P ; loop until a space is found loop_T: + StrLen ${L_LENGTH} ${L_LIST} + StrCmp ${L_LENGTH} 0 done StrCpy ${L_CHAR} ${L_LIST} 1 ; get next char from input list StrCmp ${L_CHAR} " " 0 done StrCpy ${L_LIST} ${L_LIST} "" 1 ; remove trailing spaces *************** *** 473,476 **** --- 480,484 ---- done: + Pop ${L_LENGTH} Pop ${L_CHAR} Exch ${L_PARAM} ; put parameter on stack (may be "") *************** *** 479,482 **** --- 487,491 ---- !undef L_CHAR + !undef L_LENGTH !undef L_LIST !undef L_PARAM Index: pfi-library.nsh =================================================================== RCS file: /cvsroot/popfile/windows/pfi-library.nsh,v retrieving revision 1.53.4.8 retrieving revision 1.53.4.9 diff -C2 -d -r1.53.4.8 -r1.53.4.9 *** pfi-library.nsh 21 Sep 2007 01:11:23 -0000 1.53.4.8 --- pfi-library.nsh 5 Oct 2007 18:39:24 -0000 1.53.4.9 *************** *** 59,63 **** #-------------------------------------------------------------------------- ! !define C_PFI_LIBRARY_VERSION "0.3.0" #-------------------------------------------------------------------------- --- 59,63 ---- #-------------------------------------------------------------------------- ! !define C_PFI_LIBRARY_VERSION "0.3.1" #-------------------------------------------------------------------------- *************** *** 926,938 **** Function PFI_StrStripLZS ! !define L_CHAR $R9 ! !define L_STRING $R8 Exch ${L_STRING} Push ${L_CHAR} loop: StrCpy ${L_CHAR} ${L_STRING} 1 - StrCmp ${L_CHAR} "" done StrCmp ${L_CHAR} " " strip_char StrCmp ${L_CHAR} "0" strip_char --- 926,941 ---- Function PFI_StrStripLZS ! !define L_CHAR $R9 ; current character ! !define L_LIMIT $R8 ; use string length (instead of a null) to detect end-of-string ! !define L_STRING $R7 ; the string to be processed Exch ${L_STRING} Push ${L_CHAR} + Push ${L_LIMIT} loop: + StrLen ${L_LIMIT} ${L_STRING} + StrCmp ${L_LIMIT} 0 done StrCpy ${L_CHAR} ${L_STRING} 1 StrCmp ${L_CHAR} " " strip_char StrCmp ${L_CHAR} "0" strip_char *************** *** 944,951 **** --- 947,956 ---- done: + Pop ${L_LIMIT} Pop ${L_CHAR} Exch ${L_STRING} !undef L_CHAR + !undef L_LIMIT !undef L_STRING *************** *** 4266,4311 **** Function ${UN}PFI_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" character (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 !macroend --- 4271,4335 ---- Function ${UN}PFI_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 !macroend *************** *** 4364,4395 **** Function ${UN}PFI_StrStr ! Exch $R1 ; Make $R1 the "needle", Top of stack = old$R1, haystack ! Exch ; Top of stack = haystack, old$R1 ! Exch $R2 ; Make $R2 the "haystack", Top of stack = old$R2, old$R1 ! Push $R3 ; Length of the needle ! Push $R4 ; Counter ! Push $R5 ; Temp ! StrLen $R3 $R1 ! StrCpy $R4 0 loop: ! StrCpy $R5 $R2 $R3 $R4 ! StrCmp $R5 $R1 done ! StrCmp $R5 "" done ! IntOp $R4 $R4 + 1 ! Goto loop ! done: ! StrCpy $R1 $R2 "" $R4 ! Pop $R5 ! Pop $R4 ! Pop $R3 ! Pop $R2 ! Exch $R1 ! FunctionEnd !macroend --- 4388,4452 ---- Function ${UN}PFI_StrStr ! !define L_NEEDLE $R1 ; the string we are trying to match ! !define L_HAYSTACK $R2 ; the string in which we search for a match ! !define L_NEEDLE_LENGTH $R3 ! !define L_HAYSTACK_LIMIT $R4 ! !define L_HAYSTACK_OFFSET $R5 ; the first character has an offset of zero ! !define L_SUBSTRING $R6 ; a string that might match the 'needle' string ! Exch ${L_NEEDLE} ! Exch ! Exch ${L_HAYSTACK} ! Push ${L_NEEDLE_LENGTH} ! Push ${L_HAYSTACK_LIMIT} ! Push ${L_HAYSTACK_OFFSET} ! Push ${L_SUBSTRING} ! StrLen ${L_NEEDLE_LENGTH} ${L_NEEDLE} ! StrLen ${L_HAYSTACK_LIMIT} ${L_HAYSTACK} ! ! ; If 'needle' is longer than 'haystack' then return empty string ! ; (to show 'needle' was not found in 'haystack') ! ! IntCmp ${L_NEEDLE_LENGTH} ${L_HAYSTACK_LIMIT} 0 0 not_found ! ! ; Adjust the search limit as there is no point in testing substrings ! ; which are known to be shorter than the length of the 'needle' string ! ! IntOp ${L_HAYSTACK_LIMIT} ${L_HAYSTACK_LIMIT} - ${L_NEEDLE_LENGTH} ! ! ; The first character is at offset 0 ! ! StrCpy ${L_HAYSTACK_OFFSET} 0 loop: ! StrCpy ${L_SUBSTRING} ${L_HAYSTACK} ${L_NEEDLE_LENGTH} ${L_HAYSTACK_OFFSET} ! StrCmp ${L_SUBSTRING} ${L_NEEDLE} match_found ! IntOp ${L_HAYSTACK_OFFSET} ${L_HAYSTACK_OFFSET} + 1 ! IntCmp ${L_HAYSTACK_OFFSET} ${L_HAYSTACK_LIMIT} loop loop 0 ! not_found: ! StrCpy ${L_NEEDLE} "" ! Goto exit ! match_found: ! StrCpy ${L_NEEDLE} ${L_HAYSTACK} "" ${L_HAYSTACK_OFFSET} ! exit: ! Pop ${L_SUBSTRING} ! Pop ${L_HAYSTACK_OFFSET} ! Pop ${L_HAYSTACK_LIMIT} ! Pop ${L_NEEDLE_LENGTH} ! Pop ${L_HAYSTACK} ! Exch ${L_NEEDLE} ! ! !undef L_NEEDLE ! !undef L_HAYSTACK ! !undef L_NEEDLE_LENGTH ! !undef L_HAYSTACK_LIMIT ! !undef L_HAYSTACK_OFFSET ! !undef L_SUBSTRING ! ! FunctionEnd !macroend |