Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 408805415d9839594707e1ad72d8c6b11dd0e3e2aca312eb63ef1f74a9c9392a
Ticket: 8dd2807066d7cc4d8604164f39b7f0d65c0dc321
bug in single-argument 'max' with bignums
User & Date: apnadkarni on 2025-11-13 03:56:41
Changes

  1. closedate changed to: "2460992.66436343"
  2. closer changed to: "apnadkarni"
  3. icomment:
    Sergey, your fix seems fine for the **current** implementation but I am uncomfortable with it for the following reason. 
    
    The `Tcl_GetNumberFromObj` (which the GetNumberFromObj macro translates to) say 
    
    *When callers of these routines read numeric values through the reported storage pointer, they are accessing memory that belongs to the Tcl library. The Tcl library has the power to overwrite or free this memory. The storage pointer reported by a call to Tcl_GetNumber or Tcl_GetNumberFromObj should not be used after the same thread has possibly returned control to the Tcl library.*
    
    Thus, as documented, there is no guarantee that ptr1 is even valid anymore after the second call to `GetNumberFromObj`. The implementation is assuming the same thread local storage is reused for bignums on every call. I can imagine a possibility that if an existing allocation from a previous call is too big for a smaller bignum, it is reallocated. In which case ptr1 may be != ptr2 but no longer even points to valid storage. I don't know the internal details of bignums so perhaps this is not a possible but the point is the underlying bignum implementation can change and it's safer to not rely on it from modules that are not part of bignum itself.
    
    But you and Jan are more competent to make that call; I'm just voicing my concern.
    
  4. login: "apnadkarni"
  5. mimetype: "text/x-markdown"