Skip to content
Tcl Source Code Artifact [62ba2b8f2e]
Login

Artifact [62ba2b8f2e]

Artifact 62ba2b8f2e4aeba81b708d94c03dd2def268e812:

Ticket change [62ba2b8f2e] - New ticket [218287ffffffffff|218287ffff] <i>binary scan problem with 16 bit integers &gt; 0x8000</i>. by nobody on 2000-10-26 00:55:36.
D 2000-10-26T00:55:36
J assignee nobody
J cmimetype text/plain
J comment OriginalBugID:\s3466\sBug\nVersion:\s8.0.4\nSubmitDate:\s'1999-11-05'\nLastModified:\s'2000-04-04'\nSeverity:\sMED\nStatus:\sClosed\nSubmitter:\stechsupp\nChangedBy:\shobbs\nRelatedBugIDs:\s3229\nOS:\sLinux\nFixedDate:\s'2000-10-25'\nClosedDate:\s'2000-04-04'\n\n\nName:\nBob\sFindlay\n\nReproducibleScript:\n#!/usr/bin/tclsh\n\s\s\s\sset\sbob1\s0x8000\n\s\s\s\sset\sbob2\s[binary\sformat\s"s1"\s$bob1]\n\s\s\s\sbinary\sscan\s$bob2\ss1\sbob3\n\s\s\s\sputs\sstdout\s[format\s"bob1=%X\sbob3=%X"\s$bob1\s$bob3]\n\nObservedBehavior:\nIt\sseems\sonce\sthe\slead\sbit\sin\sa\s16\sbit\sinteger\sis\sset\sthe\sbinary\n\s\s\s\sscan\scommand\sseems\sto\sprepend\sthe\sresult\swith\s0xffff\n\s\s\s\s\n\s\s\s\sThis\sdoes\snot\sseem\slike\sthe\scorrect\sbehavior.\n\nDesiredBehavior:\nI\swould\shave\sexpected\sthat\sbinary\sscan\swould\sreturn\swith\sthe\s16\sbit\n\s\s\s\svalue\s\n\s\s\s\swithout\sthe\sprepended\s0xffff\n\n\n\nThe\soutput\sdoes\scome\sout\sas\s(8.3.0):\n\n\s\s\s\sbob1=8000\sbob3=FFFF8000\n\nwhich\sdoesn't\sseem\scorrect.\s\sA\swork-around\s(possibly\sonly\sfor\nthis\sknown\scase)\sis:\n\n\s\s\s\sformat\s"bob1=%X\sbob3=%X"\s$bob1\s[expr\s{$bob3\s&\s~0xffff0000}]\n\nneeds\sfurther\sinvestigation.\s\n--\s04/03/2000\shobbs\n\nThis\sturns\sout\sto\sbe\sthe\scorrect\sbehavior,\sbased\son\swhat\sthe\nuser\sis\srequesting.\s\sFor\sshorts\s(s\sor\sS),\snumbers\s>=\s0x8000\sare\nnegative\s(we\sdon't\shave\srepresentation\sfor\sunsigned\sshorts\s-\nmaybe\swe\sshould,\sthe\ssame\sis\strue\sfor\schars\sand\salso\sints\son\nsystems\swhere\sints\sare\s>\s32\sbits).\s\sSo,\sthe\sdata\sis\sstored\sinto\nthe\sByteArray\staking\sup\sonly\s16\sbits.\s\sHowever,\swhen\sit\sis\nextracted,\sit\sis\splaced\sinto\sa\slong\svalue,\sand\sthus\sthe\ssign\nextension\smust\sbe\sdone.\s\sSo\sthe\sshort\svalue\s0x8000\sis\nequivalent\sto\sthe\slong\svalue\s0xFFFF8000\s(or\s0xFFFFFFFFFFFF8000\non\s64bit\slongs).\s\sThus,\sthe\scorrect\sway\sto\shandle\sthis,\sif\sthe\nuser\swanted\sto\swork\swith\sthe\sshorts\sbeing\sunsigned,\sis\sto\smask\neach\sreturn\svalue\swith\s0xFFFF\s($bob3\s&\s0xFFFF).\s\sThe\sabove\nwork-around\salso\sworks,\sbut\sonly\son\s32bit\ssystems,\sso\suse\sthe\nlatter\sinstead.\n\nYou\scan\ssee\sthe\scode\sand\slogic\sfor\sthis\sin\stclBinary.c:ScanNumber.\nWe\swill\sput\sa\snote\sin\sthe\sbinary\sdoc\sfor\s8.3.1\sas\sthis\sis\sa\sbit\ntricky\s(but\sdefinitely\scorrect).\s\n--\s04/04/2000\shobbs\n\nThe\sfollowing\shas\sbeen\sadded\sto\sthe\sbinary.n\sman\spage\s(scan\ssection):\n\nIt\sis\simportant\sto\snote\sthat\sthe\sc,\ss,\sand\sS\s(and\si\sand\sI\son\n64bit\ssystems)\swill\sbe\sscanned\sinto\slong\sdata\s\ssize\s\svalues.\nIn\sdoing\sthis,\svalues\sthat\shave\stheir\shigh\sbit\sset\s(0x80\sfor\nchars,\s0x8000\sfor\sshorts,\s0x80000000\sfor\sints),\swill\sbe\ssign\nextended.\s\sThus\sthe\sfollowing\swill\soccur:\nset\ssignShort\s[binary\sformat\ss1\s0x8000]\nbinary\sscan\s$signShort\ss1\sval;\s\s#\sval\s==\s0xFFFF8000\nIf\s\syou\s\swant\s\sto\s\swork-around\sthe\ssign\sextension\sof\svalues,\nmask\sthe\sreturn\svalue\sto\sthe\scorrect\ssize,\sfor\sexample\s\swith\nshorts:\nset\sval\s[expr\s{$val\s&\s0xFFFF}];\s\s#\sval\s==\s0x8000\n\s\n--\s04/04/2000\shobbs
J foundin obsolete:\s8.0.4
J priority 5\sMedium
J resolution None
J status Open
J submitter nobody
J subsystem 81.\sBundled\sPackages
J title binary\sscan\sproblem\swith\s16\sbit\sintegers\s>\s0x8000
J type Bug
K 218287ffffffffffffffffffffffffffffffffff
U nobody
Z a42eaa32c9b4978fffceb5205e76a4c6