Modify

Opened 12 years ago

Closed 12 years ago

#2841 closed Bug (Fixed)

_StringRepeat adds string once even if parsed count is zero

Reported by: RTFC Owned by: Melba23
Milestone: 3.3.13.17 Component: AutoIt
Version: 3.3.12.0 Severity: None
Keywords: stringrepeat Cc:

Description

Hi devs!
RTFC here. I use _StringRepeat with a variable count in file I/O for struct padding. This count can be zero, but one instance is always added. Id' like a count of zero to mean: "no padding."

Example

#include <String.au3>
MsgBox(0,"test",StringLen(_StringRepeat(" ",0))) ; << should be zero!!!

Annotation in <String.au3> explicitly states zero is valid input, but a final instance of string is added outside of the catenation loop, as marked below in original UDF in String.au3 (penultimate line):

Func _StringRepeat$sString, $iRepeatCount)
	; Casting Int() takes care of String/Int, Numbers.
	$iRepeatCount = Int($iRepeatCount)
	; Zero is a valid repeat integer.
	If StringLen($sString) < 1 Or $iRepeatCount < 0 Then Return SetError(1, 0, "")
	Local $sResult = ""
	While $iRepeatCount > 1
		If BitAND($iRepeatCount, 1) Then $sResult &= $sString
		$sString &= $sString
		$iRepeatCount = BitShift($iRepeatCount, 1)
	WEnd
	Return $sString & $sResult ; <<<<<< FAILS HERE <<<<
EndFunc   ;==>_StringRepeat

Thanks for looking at this,
RTFC

Attachments (0)

Change History (1)

comment:1 by Melba23, 12 years ago

Milestone: 3.3.13.17
Owner: set to Melba23
Resolution: Fixed
Status: newclosed

Fixed by revision [10898] in version: 3.3.13.17

Modify Ticket

Action
as closed The owner will remain Melba23.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.