Skip to content
Tcl Source Code History Of Ticket 26870862f0e8884e
Login

History Of Ticket 26870862f0e8884e

Artifacts Associated With Ticket 26870862f0e8884e

  1. Ticket change [f6e3968cbc] (rid 219449) by jan.nijtmans on 2023-10-15 11:51:16:

    1. assignee initialized to: "nobody"
    2. closer initialized to: "nobody"
    3. cmimetype initialized to: "text/x-fossil-wiki"
    4. comment initialized to:
      In tclAssembly.c, lines 2014 and 3454, the Tcl_SetErrorCode() is not properly ended with NULL. Adding compiler checks for this results in:
      <pre>
      generic/tclAssembly.c:2014:63: warning: missing sentinel in function call [-Wsentinel]
                      Tcl_SetErrorCode(interp, "TCL", "ASSEM", "DUPJUMPTABLEENTRY");
                                                                                  ^
      generic/tclAssembly.c:3454:64: warning: missing sentinel in function call [-Wsentinel]
                  Tcl_SetErrorCode(interp, "TCL", "ASSEM", "BADSTACKINCATCH", -1);
                                                                                ^
      </pre>
      
      Those two instances will lead to a crash, when encoungered. Apparently, there is no testcase for it (which would - indeed - be difficult to write)
      
      It would be good to implement compiler-checks for this, even in 8.6
      
    5. foundin initialized to: "8.6"
    6. is_private initialized to: "0"
    7. login: "jan.nijtmans"
    8. priority initialized to: "5 Medium"
    9. private_contact initialized to: "0c50e5320704d174412e57b873d8932de15303e0"
    10. resolution initialized to: "None"
    11. severity initialized to: "Critical"
    12. status initialized to: "Open"
    13. submitter initialized to: "jan.nijtmans"
    14. subsystem initialized to: "52. Portability Support"
    15. title initialized to: "Wrong sentinel in Tcl_SetErrorCode usage"
    16. type initialized to: "Bug"
  2. Ticket change [16d5a9cd0b] (rid 219474) by jan.nijtmans on 2023-10-15 22:03:02:

    1. assignee changed to: "jan.nijtmans"
    2. icomment:
      Fixed [1317d7d04f7f3437|here].
      
      Leaving open: let's add better checks
      
    3. login: "jan.nijtmans"
    4. mimetype: "text/x-fossil-wiki"
  3. Ticket change [fdee532212] (rid 219602) by jan.nijtmans on 2023-10-19 18:19:28:

    1. icomment:
      Addition: For C++-compilers, the problem is that some C++-compilers (e.g. clang-8.0.1) define "NULL" as identical to "0", which is allowed in C++-land. See: [https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95700]
      
      The only way which should work with all C++-compilers is using (void *)NULL.
      
      In C, this is no problem. We don't want to force extension-writers to do the same: Many extensions don't care about C++.
      
      C++-case handled [234ff497c44f843c|here]
      
      Still keeping open, it would be nice to have the compiler check for this by default.
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
    4. resolution changed to: "Fixed"
    5. severity changed to: "Severe"
    6. status changed to: "Pending"
  4. Ticket change [f9a87c64ab] (rid 219635) by gustafn3 on 2023-10-20 07:53:09:

    1. icomment:
      Passing NULL after the last typed argument to a variadic function is not
      recommended either, since this leads to undefined behaviour. 
      This construct will lead e.g. to the following error flagged by cppcheck:
      
      ==========================================================================================
      generic/tclBinary.c:403:52: portability: Passing NULL after the last 
      typed argument to a variadic function leads to undefined behaviour.
      
      The C99 standard, in section 7.15.1.1, states that if the type used 
      by va_arg() is not compatible with the type of the actual next argument 
      (as promoted according to the default argument promotions), the behavior is undefined.
      
      The value of the NULL macro is an implementation-defined null pointer 
      constant (7.17), which can be any integer constant expression with the value 0, 
      or such an expression casted to (void*) (6.3.2.3). This includes values like 
      0, 0L, or even 0LL.
      
      In practice on common architectures, this will cause real crashes if 
      sizeof(int) != sizeof(void*), and NULL is defined to 0 or any other 
      null pointer constant that promotes to int.
      
      To reproduce you might be able to use this little code example on 64bit
      platforms. If the output includes "ERROR", the sentinel had only 4 out of 
      8 bytes initialized to zero and was not detected as the final argument to 
      stop argument processing via va_arg(). Changing the 0 to (void*)0 or 0L 
      will make the "ERROR" output go away.
      
        Tcl_SetErrorCode(interp, "TCL", "API", "OUTDATED", NULL);
      ==========================================================================================
      
      In NaviServer such occurrences have been replaced by using "(char *)0L" 
      instead of "NULL" after the last typed argument. Here are some examples 
      concerning Tcl_SetErrorCode():
      
      ==========================================================================================
      nsd/tcljob.c:                    Tcl_SetErrorCode(interp, "NS_TIMEOUT", (char *)0L);
      nsd/tcljob.c:                    Tcl_SetErrorCode(interp, jobPtr->errorCode, (char *)0L);
      nsd/tcljob.c:                    Tcl_SetErrorCode(interp, "NS_TIMEOUT", (char *)0L);
      nsd/tcljob.c:        Tcl_SetErrorCode(interp, "ECANCEL", (char *)0L);
      nsd/tclobjv.c:        Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "INDEX", msg, key, (char *)0L);
      nsd/tclvar.c:                    Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "NSV", "KEY", keyString, (char *)0L);
      nsd/tclvar.c:                Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "NSV", "KEY", keyString, (char *)0L);
      nsd/tclvar.c:                Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "NSV", "KEY", keyString, (char *)0L);
      nsd/tclvar.c:            Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "NSV", "KEY", keyString, (char *)0L);
      nsd/tclvar.c:                                    Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "DICT",
      nsd/tclvar.c:        Tcl_SetErrorCode(interp, "TCL", "LOOKUP", "NSV", "ARRAY", arrayName, (char *)0L);
      nsd/tls.c:        Tcl_SetErrorCode(interp, "OPENSSL", errorBuf, (char *)0L);
      nsd/urlencode.c:            Tcl_SetErrorCode(interp, "NS_INVALID_UTF8", NULL);
      ==========================================================================================
      
      If there is interest, i can provide a fixed branch for such issues.
      
    2. login: "gustafn3"
    3. mimetype: "text/plain"
  5. Ticket change [6c419b899c] (rid 219636) by jan.nijtmans on 2023-10-20 08:14:25:

    1. icomment:
      @gustaf wrote:
      > If there is interest, i can provide a fixed branch for such issues
      
      See: [234ff497c44f843c]. All such occurrences of "NULL" have been replaced now by (void *)NULL, exactly for the reason you mention: NULL is non-portable in this situation.
      
      I never saw this problem on any C-compiler, but I saw it happen in C++ with clang-8.0.1.
      
      Hope this helps,
            Jan Nijtmans
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/plain"
  6. Ticket change [f91019b8f5] (rid 219637) by jan.nijtmans on 2023-10-20 08:14:48:

    1. icomment:
      @gustaf wrote:
      > If there is interest, i can provide a fixed branch for such issues
      
      See: [234ff497c44f843c]. All such occurrences of "NULL" have been replaced now by (void *)NULL, exactly for the reason you mention: NULL is non-portable in this situation.
      
      I never saw this problem on any C-compiler, but I saw it happen in C++ with clang-8.0.1.
      
      Hope this helps,
            Jan Nijtmans
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  7. Ticket change [2cc9da4a5b] (rid 219641) by gustafn3 on 2023-10-20 09:02:59:

    1. icomment:
      > All such occurrences of "NULL" have been replaced ...
      
      Well, AFIKT not all (at least in the current "trunk" branch after a "fossil pull && fossil update"):
      e.g.
         generic/tclBinary.c: 403
         generic/tclBinary.c: 522
         generic/tclCompile.c: 2200
         ...
      
      > ... by (void *)NULL
      Maybe, i am too conservative, but "(char *)0L" is fully safe imho.
      
      The problem is, that is that the construct is implementation dependent, 
      people use different compilers on different OSes and platforms, .... 
      We all know, "not seen so far" is a way is a weak argument.
      
    2. login: "gustafn3"
    3. mimetype: "text/plain"
  8. Ticket change [3329b6a1b8] (rid 219655) by jan.nijtmans on 2023-10-20 18:42:39:

    1. icomment:
      >Well, AFIKT not all (at least in the current "trunk" branch
      
      That's why this ticket is still "pending"... :-)
      
    2. login: "jan.nijtmans"
    3. mimetype: "text/x-fossil-wiki"
  9. Ticket change [a1d144e9e4] (rid 220881) by jan.nijtmans on 2023-12-08 15:40:45:

    1. closedate changed to: "2460287.15330685"
    2. closer changed to: "jan.nijtmans"
    3. login: "jan.nijtmans"
    4. mimetype: "text/plain"
    5. status changed to: "Closed"