Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 476bce161d3fe8dd4bc5ed29d85c270dbf0cd0b2
Ticket: 957dbe231ccd7f311b583ebe47da716db43c0641
Missing parentheses in #define LABEL 1<<1
User & Date: fvanderhave on 2016-06-03 09:32:58
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/plain"
  4. comment changed 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 changed to: "8.6"
  6. is_private changed to: "0"
  7. login: "fvanderhave"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "77b78217bda604844f1ebd4c005e3cb7fbc8be50"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "fvanderhave"
  14. subsystem changed to: "80. Thread Package"
  15. title changed to: "Missing parentheses in #define LABEL 1<<1"
  16. type changed to: "Bug"