Skip to content
Tcl Source Code History Of Ticket 218287
Login

History Of Ticket 218287

Artifacts Associated With Ticket 218287

  1. Ticket change [62ba2b8f2e] (rid 92453) by nobody on 2000-10-26 00:55:36:

    1. assignee initialized to: "nobody"
    2. cmimetype initialized to: "text/plain"
    3. comment initialized to:
      OriginalBugID: 3466 Bug
      Version: 8.0.4
      SubmitDate: '1999-11-05'
      LastModified: '2000-04-04'
      Severity: MED
      Status: Closed
      Submitter: techsupp
      ChangedBy: hobbs
      RelatedBugIDs: 3229
      OS: Linux
      FixedDate: '2000-10-25'
      ClosedDate: '2000-04-04'
      
      
      Name:
      Bob Findlay
      
      ReproducibleScript:
      #!/usr/bin/tclsh
          set bob1 0x8000
          set bob2 [binary format "s1" $bob1]
          binary scan $bob2 s1 bob3
          puts stdout [format "bob1=%X bob3=%X" $bob1 $bob3]
      
      ObservedBehavior:
      It seems once the lead bit in a 16 bit integer is set the binary
          scan command seems to prepend the result with 0xffff
          
          This does not seem like the correct behavior.
      
      DesiredBehavior:
      I would have expected that binary scan would return with the 16 bit
          value 
          without the prepended 0xffff
      
      
      
      The output does come out as (8.3.0):
      
          bob1=8000 bob3=FFFF8000
      
      which doesn't seem correct.  A work-around (possibly only for
      this known case) is:
      
          format "bob1=%X bob3=%X" $bob1 [expr {$bob3 & ~0xffff0000}]
      
      needs further investigation. 
      -- 04/03/2000 hobbs
      
      This turns out to be the correct behavior, based on what the
      user is requesting.  For shorts (s or S), numbers >= 0x8000 are
      negative (we don't have representation for unsigned shorts -
      maybe we should, the same is true for chars and also ints on
      systems where ints are > 32 bits).  So, the data is stored into
      the ByteArray taking up only 16 bits.  However, when it is
      extracted, it is placed into a long value, and thus the sign
      extension must be done.  So the short value 0x8000 is
      equivalent to the long value 0xFFFF8000 (or 0xFFFFFFFFFFFF8000
      on 64bit longs).  Thus, the correct way to handle this, if the
      user wanted to work with the shorts being unsigned, is to mask
      each return value with 0xFFFF ($bob3 & 0xFFFF).  The above
      work-around also works, but only on 32bit systems, so use the
      latter instead.
      
      You can see the code and logic for this in tclBinary.c:ScanNumber.
      We will put a note in the binary doc for 8.3.1 as this is a bit
      tricky (but definitely correct). 
      -- 04/04/2000 hobbs
      
      The following has been added to the binary.n man page (scan section):
      
      It is important to note that the c, s, and S (and i and I on
      64bit systems) will be scanned into long data  size  values.
      In doing this, values that have their high bit set (0x80 for
      chars, 0x8000 for shorts, 0x80000000 for ints), will be sign
      extended.  Thus the following will occur:
      set signShort [binary format s1 0x8000]
      binary scan $signShort s1 val;  # val == 0xFFFF8000
      If  you  want  to  work-around the sign extension of values,
      mask the return value to the correct size, for example  with
      shorts:
      set val [expr {$val & 0xFFFF}];  # val == 0x8000
       
      -- 04/04/2000 hobbs
      
    4. foundin initialized to: "obsolete: 8.0.4"
    5. priority initialized to: "5 Medium"
    6. resolution initialized to: "None"
    7. status initialized to: "Open"
    8. submitter initialized to: "nobody"
    9. subsystem initialized to: "81. Bundled Packages"
    10. title initialized to: "binary scan problem with 16 bit integers > 0x8000"
    11. type initialized to: "Bug"
  2. Ticket change [42396808aa] (rid 116331) by welch on 2000-10-26 08:18:58:

    1. closedate changed to: "2000-10-26T01:18:58"
    2. closer changed to: "welch"
    3. priority changed to: "2"
    4. resolution changed to: "Fixed"
    5. status changed to: "Closed"
  3. Ticket change [9a23f4dc46] (rid 110904) by dgp on 2001-04-05 07:21:26:

    1. subsystem changed to: "12. ByteArray Object"
  4. Ticket change [6d71d45195] (rid 128700) by dgp on 2001-04-05 07:21:27:

    1. closedate changed to: "2001-04-05T00:21:27"
    2. closer changed to: "dgp"