• Re: Which tools are available for catching UB?

    From Kenny McCormack@21:1/5 to [email protected] on Fri Jan 19 03:08:17 2024
    In article <[email protected]>,
    Kaz Kylheku <[email protected]> wrote:
    On 2024-01-11, Anthony Cuozzo <[email protected]> wrote:
    Are there any other tools out there besides what ships with e.g., GCC &
    Clang?

    All the tools that waste their time hanging out on comp.lang.c are
    pretty good for catching UB.

    Well done, sir!

    (nice play on the word "tool")

    --
    Note that Oprah actually is all the things that The Donald only wishes he were. For one thing, she actually *is* a billionaire. She's also actually self-made, came from nothing, knows how to run businesses, never went bankrupt, is smart and is mentally stable.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Lew Pitcher on Thu Jan 25 19:57:53 2024
    Lew Pitcher <[email protected]> writes:

    [A] single call to a function not defined by your program source
    code or by the ISO C standard will invoke "undefined behaviour".

    That isn't right. The C standard allows previously translated
    translation units "[to] be preserved individually or in libraries."
    Those translation units don't have to be your own code or even
    necessarily stored, or translated, on the same machine. In
    translation phase 8, "[l]ibrary components are linked to satisfy
    external references to functions and objects not defined in the
    current translation." The C standard doesn't specify how the
    libraries are located, or even require that you be able to inspect
    them, but clearly does require that libraries be consulted to satisfy
    external references. We don't know what code in the libraries will
    do, but there is a requirement /on the implementation/ that they be
    linked against in phase 8. The presence of that requirement means
    that linking to, or calling, such an external reference is not ipso
    facto undefined behavior. (Obviously it could be undefined behavior
    for other reasons, but not just by virtue of there being a call.)

    Not knowing what something will do is not the same as undefined
    behavior. The question is Does the C standard give a requirement
    about what implementations have to do? In this case it does. An implementation is not free to do whatever it wants just because a
    library was previously translated on a different machine. Code in
    a library might (emphasis _might_) provoke undefined behavior if it
    is called, but that depends on what the library code is, and is not
    something an implementation can just arbitrarily chose to do on its
    own. It's important to understand the difference.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to Tim Rentsch on Fri Jan 26 04:52:39 2024
    On 2024-01-26, Tim Rentsch <[email protected]> wrote:
    Lew Pitcher <[email protected]> writes:

    [A] single call to a function not defined by your program source
    code or by the ISO C standard will invoke "undefined behaviour".

    That isn't right. The C standard allows previously translated
    translation units "[to] be preserved individually or in libraries."
    Those translation units don't have to be your own code or even
    necessarily stored, or translated, on the same machine.

    This is a strawman interpretation of what Lew is almost certainly
    saying, which is the salient point that using a function that is not
    somewhere in your program (any translation unit from your sources or any translated units you brought to the table yourself), and not in the
    standard, is undefined behavior.

    He can't be literally saying that calling a function foo is undefined
    behavior, even if it's found in a libfoo.a that is brought from
    another machine, and which has no compatibility issues (like wrong architecture, unsupported object format, wrong ABI), and is being linked
    to the program, and used correctly according to its documentation.

    That would be silly, and uncharacteristic of Lew's level of experience,
    so it can't be the right interpretation.

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Tim Rentsch@21:1/5 to Kaz Kylheku on Sat Feb 10 02:06:40 2024
    Kaz Kylheku <[email protected]> writes:

    On 2024-01-26, Tim Rentsch <[email protected]> wrote:

    Lew Pitcher <[email protected]> writes:

    [A] single call to a function not defined by your program source
    code or by the ISO C standard will invoke "undefined behaviour".

    That isn't right. The C standard allows previously translated
    translation units "[to] be preserved individually or in libraries."
    Those translation units don't have to be your own code or even
    necessarily stored, or translated, on the same machine.

    This is a strawman interpretation of what Lew is almost certainly
    saying,

    No, it isn't. You misunderstood my statement.

    which is the salient point that using a function that is not
    somewhere in your program (any translation unit from your sources
    or any translated units you brought to the table yourself), and
    not in the standard, is undefined behavior.

    No, it isn't. Whether a library, for example, was something you put
    on the machine yourself, or was put there by a hacker without your
    knowledge, doesn't affect the presence or absence of undefined
    behavior. All that matters is what's in the library. It's
    perfectly possible for a library installed by a hacker to perform
    only well-defined operations, be well-formed and ABI-compatible,
    etc. Just because you don't know what is in the library doesn't
    make it undefined behavior.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)