Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2017-04-28
14:16 • Closed ticket [04e26c02c0]: Warning plus 4 other changes artifact: a2838d8a4e user: dgp
06:04 • Open ticket [04e26c02c0]. artifact: 48488ed74f user: gahr
2017-04-27
17:26 • Closed ticket [04e26c02c0]. artifact: fb5e6865a7 user: dgp
17:26
[04e26c02c0] Remove useless condition that raises warnings. check-in: e47f5822c0 user: dgp tags: trunk
17:19
[04e26c02c0] Remove useless condition that raises warnings. check-in: 1fd3e94447 user: dgp tags: core-8-6-branch
17:02
[04e26c02c0] Remove useless condition that raises warnings. check-in: 7136600525 user: dgp tags: core-8-5-branch
16:34 • Ticket [04e26c02c0] Warning status still Open with 3 other changes artifact: d4ee6d3d84 user: dgp
13:47 • Ticket [04e26c02c0]: 3 changes artifact: 9cf9936d57 user: dgp
10:37 • Ticket [04e26c02c0]: 4 changes artifact: a3af971578 user: gahr
10:37
[04e26c02c0] Provide an unsafe version of the GetNumberFromObj for use when we know the arguments ar... check-in: 98eb0f7628 user: gahr tags: tkt-04e26c02c0
10:35 • New ticket [04e26c02c0] Warning. artifact: 03dea3bd30 user: gahr

Warning

Closed / Fixed04e26c02c04596869907b5240ffa0c97457df352Created 10 years agoUpdated 10 years ago
Descriptionplain2017-04-27 10:35:36
Warning in tclExecute.c. A branch is never taken - TclCompareTwoNumbers states as prerequisite that the arguments are known to be of numeric and not NaN - but the compiler doesn't know it.

generic/tclExecute.c:9244:12: warning: variable 'type1' is used uninitialized whenever '?:' condition is true [-Wsometimes-uninitialized]                                                                                                                                 
    (void) GetNumberFromObj(NULL, valuePtr, &ptr1, &type1);                     
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                      
generic/tclExecute.c:513:5: note: expanded from macro 'GetNumberFromObj'                                  
    ((((objPtr)->typePtr == NULL) && ((objPtr)->bytes == NULL)) ||      \       
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~       
generic/tclExecute.c:9247:13: note: uninitialized use occurs here                                         
    switch (type1) {                                                            
            ^~~~~                                                               
generic/tclExecute.c:9244:12: note: remove the '?:' if its condition is always false                      
    (void) GetNumberFromObj(NULL, valuePtr, &ptr1, &type1);                     
           ^                                                                    
generic/tclExecute.c:513:5: note: expanded from macro 'GetNumberFromObj'                                  
    ((((objPtr)->typePtr == NULL) && ((objPtr)->bytes == NULL)) ||      \       
    ^
Referenced by4
gahr (claiming to be [email protected])plain2017-04-27 10:37:53
A fix is available in the [tkt-04e26c02c0] branch.
dgpplain2017-04-27 13:47:00
It appears the error is in testing this condition at all:

((objPtr)->typePtr == NULL) && ((objPtr)->bytes == NULL))

A valid Tcl_Obj must follow the stork model. It must be
standing on at least one leg.  The condition above is
testing

  "If this stork is standing on 0 legs..."

which has to always report false.

Removing that seems to be the better solution, unless
we can find some reason it was placed there that makes
sense.
dgpplain2017-04-27 16:34:53
That test is present to preserve the same test
done in earlier versions of the bytecode engine
that trace back to this March 2000 "optimization":

http://core.tcl.tk/tcl/info/6f0ee764c164f12f

Best I can tell, that was just always (harmlessly)
wrong, testing a condition that always has a known
truth value.  The comment alongside it is just 
blatantly false.  Even back in that day, we were
using tclEmptyString to represent our empty strings.
A NULL objPtr->bytes was always a sign of a pure
internal value, unless someone can show me otherwise.

Whether it was always wrong, or became outdated and wrong,
no need to keep the vestige anymore.
dgpplain2017-04-27 17:26:57
fixed on all dev branches.
gahrplain2017-04-28 06:04:42
I fear this won't be enough: there is still an error case that isn't checked by the two expansions in TclCompareTwoNumbers. This function assumes that the objects are of some numeric type, so the value of the expression is just discarded and type is expected to be set after the expansion.


generic/tclExecute.c:9242:12: warning: variable 'type1' is used uninitialized whenever '?:' condition is true
      [-Wsometimes-uninitialized]
    (void) GetNumberFromObj(NULL, valuePtr, &ptr1, &type1);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
generic/tclExecute.c:513:5: note: expanded from macro 'GetNumberFromObj'
    (((objPtr)->bytes != NULL) && ((objPtr)->length == 0))              \
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
generic/tclExecute.c:9245:13: note: uninitialized use occurs here
    switch (type1) {
            ^~~~~
generic/tclExecute.c:9242:12: note: remove the '?:' if its condition is always false
    (void) GetNumberFromObj(NULL, valuePtr, &ptr1, &type1);
           ^
generic/tclExecute.c:513:5: note: expanded from macro 'GetNumberFromObj'
    (((objPtr)->bytes != NULL) && ((objPtr)->length == 0))              \
    ^
generic/tclExecute.c:9233:14: note: initialize the variable 'type1' to silence this warning
    int type1, type2, compare;
             ^
              = 0
1 warning generated.
dgp Closed ticket [04e26c02c0]. [History diff]2017-04-28 14:16:27
Log in (anonymous is fine) to add a comment.