Modify

Opened 6 years ago

Closed 6 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 Changed 6 years ago by Melba23

  • Milestone set to 3.3.13.17
  • Owner set to Melba23
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [10898] in version: 3.3.13.17

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain Melba23.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.