• Bug#962772: valgrind thinks that size_t is signed

    From Vincent Lefevre@21:1/5 to Vincent Lefevre on Sat Dec 28 04:00:01 2024
    Control: found -1 1:3.19.0-1

    On 2020-06-13 20:06:26 +0200, Vincent Lefevre wrote:
    Package: valgrind
    Version: 1:3.15.0-1
    Severity: normal

    When testing GNU MPFR with valgrind:
    [...]

    Note that this is no longer reproducible with the latest version of
    the MPFR (or perhaps I need to pass some specific configure options,
    I don't remember...). Anyway, the issue is still reproducible with a
    simple testcase:

    #include <stdlib.h>
    int main (void)
    {
    void *p = malloc ((size_t) -1);
    return p != NULL;
    }

    qaa% gcc-snapshot tst.c -o tst
    tst.c: In function 'main':
    tst.c:4:13: warning: argument 1 value '18446744073709551615' exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
    4 | void *p = malloc ((size_t) -1);
    | ^~~~~~~~~~~~~~~~~~~~
    In file included from tst.c:1:
    /usr/include/stdlib.h:672:14: note: in a call to allocation function 'malloc' declared here
    672 | extern void *malloc (size_t __size) __THROW __attribute_malloc__
    | ^~~~~~
    qaa% valgrind ./tst
    [...]
    ==1153312== Argument 'size' of function malloc has a fishy (possibly negative) value: -1
    ==1153312== at 0x48437B4: malloc (vg_replace_malloc.c:381)
    ==1153312== by 0x401139: main (in /home/vinc17/tst)
    [...]

    GCC is right about the value (a very large positive value) in its
    warning, but valgrind is still wrong as seeing it as negative.

    --
    Vincent LefΦvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
    100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
    Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

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