Skip to content
Tcl Source Code History Of Ticket 957dbe231ccd7f31
Login

History Of Ticket 957dbe231ccd7f31

Artifacts Associated With Ticket 957dbe231ccd7f31

  1. Ticket change [476bce161d] (rid 146884) by fvanderhave on 2016-06-03 09:32:58:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/plain"
    4. comment initialized to:
      In tcl 8.6 there seems to be a bug of missing parentheses in the thread package.
      At the top of the file tcl8.6.1/pkgs/thread2.7.0/generic/threadCmd.c
      there is a definition 
      #define THREAD_SEND_WAIT 1<<1
      #define THREAD_SEND_HEAD 1<<2
      
      It seems to me that this is intended to define which specific one bit to use in
      bitwise operations. These are used for example in ThreadSendObjCmd() in a
      line like: 
      
      if (OPT_CMP(arg, "-async")) {
              flags &= ~THREAD_SEND_WAIT;
           }
      
      The problem is that the operator precedence of the bitwise not ("~") is
      higher than the the precedence of the shift left ("<<"). While the
      intended result seems to be to compute 
           flags &= ~(1<<1);
      what is actually computed is
           flags &= (~1)<<1;
      
      As long as this operation is only done on the least significant used
      bit out of all bits in the bit mask, this "bug" probably has no practical 
      effect, except invoking undefined behavior of shifting into and past the sign
      bit of a signed value. However, if it is indeed a bug, it has the
      potential to become a hard-to-notice more serious problem with later
      code changes. 
      
      Please verify whether the intention is indeed to clear out one single bit,
      or that it clears also all bits that are less significant at the same time.
      In case the intention is to use 1<<1 and 1<<2 to specify a single bit in
      a bit-mask, my recommendation would be to include parentheses:
      #define THREAD_SEND_WAIT (1<<1)
      #define THREAD_SEND_HEAD (1<<2)
      
      The same problem and suggested fix applies to these three lines in the
      newer version in tcl8.6.5/pkgs/thread2.7.3/generic/threadCmd.c:
      #define THREAD_SEND_WAIT 1<<1
      #define THREAD_SEND_HEAD 1<<2
      #define THREAD_SEND_CLBK 1<<3
      
      Best regards,
      Frans van der Have,
      developer at Scientific Volume Imaging.
      
    5. foundin initialized to: "8.6"
    6. is_private initialized to: "0"
    7. login: "fvanderhave"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "77b78217bda604844f1ebd4c005e3cb7fbc8be50"
    10. resolution initialized to: "None"
    11. severity initialized to: "Minor"
    12. status initialized to: "Open"
    13. submitter initialized to: "fvanderhave"
    14. subsystem initialized to: "80. Thread Package"
    15. title initialized to: "Missing parentheses in #define LABEL 1<<1"
    16. type initialized to: "Bug"
  2. Ticket change [9c1195a3c5] (rid 146888) by gahr on 2016-06-03 13:21:57:

    1. closedate changed to: "2457543.05691707"
    2. closer changed to: "gahr"
    3. icomment:
      Fixed in [http://core.tcl.tk/thread/info/b52389dd2464bdb1]. Thanks!
      
    4. login: "gahr"
    5. mimetype: "text/x-fossil-wiki"
    6. resolution changed to: "Fixed"
    7. status changed to: "Closed"
    8. username: "gahr"