Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: cb73bae87ffbb8a159a343cc31355b4f327a46a2162c00d0b8e9fa9d8205dd26
Ticket: 8ab8a138c9156e5a5a4a386310c6fd11608b8805
Functions passed to Tcl_EventuallyFree() must be declared/defined as Tcl_FreeProc
User & Date: chrstphrchvz on 2023-10-07 12:30:45
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    LLVM Clang 17 makes <tt>-fsanitize=function</tt> available for C (previously it was just for C++). It is implied by <tt>-fsanitize=undefined</tt>. It complains about calls to <tt>freeProc(clientData)</tt> from <tt>Tcl_EventuallyFree()</tt> and <tt>Tcl_Release()</tt>. Unlike warnings from e.g. <tt>-Wincompatible-function-pointer-types</tt>, this UBSan error is not suppressed by casts to <tt>(Tcl_FreeProc *)</tt>. Example when exiting tclsh:
    <pre>
    <span style="font-weight:bold">tcl/generic/tclPreserve.c:229:3: <span style="color:firebrick">runtime error:</span> call to function DeleteInterpProc through pointer to incorrect function type 'void (*)(char *)'
    tclBasic.c:1422: <span style="color:gray">note:</span></span> DeleteInterpProc defined here
    SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcl/generic/tclPreserve.c:229:3 in 
    </pre>
    There are only a few of instances of this in core Tcl; to patch these, I remove casts to <tt>(Tcl_FreeProc *)</tt>, then use the <tt>Tcl_FreeProc</tt> typedef for function declarations, and then fix function definitions. There are several more instances in core Tk which I am looking into patching. Any extensions passing incompatible function pointers to <tt>Tcl_EventuallyFree()</tt> will also trigger this UBSan error.
    
  5. foundin changed to: "8.6.13"
  6. is_private changed to: "0"
  7. login: "chrstphrchvz"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "6133eb3026f9b10aa9b7b48da92ae2834fc225b0"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "chrstphrchvz"
  14. subsystem changed to: "42. Memory Preservation"
  15. title changed to:
    Do not pass incompatible function pointers to Tcl_EventuallyFree()
    
  16. type changed to: "Patch"