Modify

Opened 10 years ago

Closed 10 years ago

#2992 closed Bug (No Bug)

Int, Dec, Number return incorrect results when used with binary and string data

Reported by: timsky Owned by:
Milestone: Component: AutoIt
Version: 3.3.12.0 Severity: None
Keywords: Int, Dec, Number Cc:

Description

Forum bug report: http://www.autoitscript.com/forum/topic/167633-int-returns-incorrect-results

1) Int and Number of binary data works fine on 1-byte data only. 2+ byte binary data always returns incorrect results.
2) Case of 4-byte (32 bit) binary data and it's string representation:

a) Int and Number of 4-byte binary data returns wrong result.
b) Int (64 bit flag) of string representation of 4-byte binary data returns 32-bit signed integer. Example string "0xffd88d8a" return -2585206 instead of 4292382090.
c) Only Dec (64 bit flag) and Number (double flag) return correct results.

3) Number (double flag) does not work on binary data always. It returns 0.
4) Number (double flag) stop working on string data starting 5+ byte data. It returns 0.
5) Dec (double flag) doesn't work always. It returns strange numbers like 1.25986739689518e-321 for "0xff".

Demo code:

Global $aBin[] = ["0xff", '0xffd8', '0xffd88d', '0xffd88d8a', '0xffd88d8abc', '0xffd88d8abcd1', '0xffd88d8abcd1e5', '0xffd88d8abcd1e5ff']

For $i = 0 To UBound($aBin) - 1
    $real_str = $aBin[$i]
    $real_bin = Binary($real_str)
    ; MsgBox(0, VarGetType($real_str), VarGetType($real_bin))

    $sData = 'Hex: ' & @TAB & @TAB & $real_str & @LF & _
            'Binary: ' & @TAB & @TAB & StringLower($real_bin) & @LF & _
            'Dec32: ' & @TAB & @TAB & Dec(StringTrimLeft($real_str, 2), 1) & @LF & _	; added
            'Dec:  (auto)' & @TAB & @TAB & Dec(StringTrimLeft($real_str, 2)) & @LF & _	; Renamed
            'Dec64: ' & @TAB & @TAB & Dec(StringTrimLeft($real_str, 2), 2) & @LF & _	; added
            'Dec (double): ' & @TAB & @TAB & Dec(StringTrimLeft($real_str, 2), 3) & @LF & _	; added
            'Number32 <- String: ' & @TAB & @TAB & Number($real_str, 1) & @LF & _	; added
            'Number <- String:  (auto)' & @TAB & @TAB & Number($real_str) & @LF & _	; added
            'Number64 <- String: ' & @TAB & @TAB & Number($real_str, 2) & @LF & _	; added
            'Number (double) <- String: ' & @TAB & @TAB & Number($real_str, 3) & @LF & _	; added
            'Number32 <- Binary ' & @TAB & @TAB & Number($real_bin, 1) & @LF & _	; added
            'Number <- Binary  (auto)' & @TAB & @TAB & Number($real_bin) & @LF & _	; added
            'Number64 <- Binary ' & @TAB & @TAB & Number($real_bin, 2) & @LF & _	; added
            'Number (double) <- Binary ' & @TAB & @TAB & Number($real_bin, 3) & @LF & _	; added
            'Int32: ' & @TAB & @TAB & Int($real_str, 1) & @LF & _
            'Int (auto): ' & @TAB & @TAB & Int($real_str) & @LF & _
            'Int64: ' & @TAB & @TAB & Int($real_str, 2) & @LF & _
            'Int32 <- String: ' & @TAB & Int(String($real_str), 1) & @LF & _
            'Int (auto) <- String: ' & @TAB & Int(String($real_str)) & @LF & _
            'Int64 <- String: ' & @TAB & Int(String($real_str), 2) & @LF & _
            'Int32 <- Binary: ' & @TAB & Int($real_bin, 1) & @LF & _
            'Int (auto) <- Binary: ' & @TAB & Int($real_bin) & @LF & _
            'Int64 <- Binary: ' & @TAB & Int($real_bin, 2)

    MsgBox(524288, $real_str & " - " & BinaryLen($real_str) & ' bytes', $sData)

Next

So right now the only working way to interpret Binary data in 8-64 bit range is Dec with 64 bit flag set.
And bugfix for 3.3.12.0 "Fixed #2581: Dec() wasn't working correctly for flags 0, 1, 2" seems like is not fully completed.

AutoIt 3.3.12.0 / 3.3.13.19. x86 and x64
OS: Win 7 x64 SP1

Attachments (0)

Change History (2)

comment:2 Changed 10 years ago by BrewManNH

  • Resolution set to No Bug
  • Status changed from new to closed

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 ticket will remain with no owner.
Author


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

 
Note: See TracTickets for help on using tickets.