Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2002-11-28
05:55 • Closed ticket [618852ffff]: possibly logic error in tclWinChan.c plus 2 othe... artifact: 84d04e8d0d user: davygrvy
05:55 • Ticket [618852ffff]: 5 changes artifact: 0cc934afb5 user: davygrvy
2002-10-08
19:35 • Ticket [618852ffff]: 2 changes artifact: b920fba0e6 user: dkf
2002-10-05
05:09 • New ticket [618852ffff]. artifact: fd8c910d7e user: nobody

possibly logic error in tclWinChan.c

Closed / Fixed618852ffffffffffffffffffffffffffffffffffCreated 24 years agoUpdated 24 years ago
Descriptionplain2002-10-05 05:09:03
While cruising through the Tcl source code, i found 
this code.

tclWinChan.c starting at line #1023:

    default:
/*
 * The handle is of an unknown type.  
Test the validity of this OS
 * handle by duplicating it, then closing 
the dupe.  The Win32 API
 * doesn't provide an IsValidHandle() 
function, so we have to emulate
 * it here.  This test will not work on a 
console handle reliably,
 * which is why we can't test every handle 
that comes into this
 * function in this way.
 */

result = DuplicateHandle
(GetCurrentProcess(), handle,
GetCurrentProcess(), 
&dupedHandle, 0, FALSE,
DUPLICATE_SAME_ACCESS);

if (result != 0) {
    /* 
     * Unable to make a duplicate. It's 
definately invalid at this
     * point.
     */

    return NULL;
}

------------------------

The above code does not appear to be correct.  The 
DuplicateHandle function returns non-zero to 
indicate SUCCESS, not failure.  If the intent (??) of 
the above code is to bail out in case of error, then 
it is definately not correct.  I believe the correct if 
statement would check for (result == 0).

I think somebody should take a close look at this 
logic to make sure I am not confused.  

A cursory search of the Tcl/Tk source trees reveals 
no other places where DuplicateHandle is being 
called AND where the caller relies upon it's return 
code.

------------------------

From the SDK:

Return Values
If the function succeeds, the return value is 
nonzero.

If the function fails, the return value is zero. To get 
extended error information, call GetLastError. 

------------------------

JJM
dkf Ticket [618852ffff]: 2 changes [History diff]2002-10-08 19:35:38
davygrvyplain2002-11-28 05:55:33
Logged In: YES 
user_id=7549

whoops...  fixed...
davygrvy Closed ticket [618852ffff]. [History diff]2002-11-28 05:55:52
Log in (anonymous is fine) to add a comment.