Skip to content

(UndefinedBehaviorSanitizer) GrowableArray.h: null pointer passed as argument 2, which is declared to never be null  #102

@blockspacer

Description

@blockspacer
#~/.conan/data/corrade/v2020.06/conan/stable/build/#a588aedb50aa745a2698801b1f638aec5f70dbcd/src/Corrade/Containers/#GrowableArray.h:943:22: runtime error: null pointer passed as argument 2, which is #declared to never be null
#/usr/include/string.h:43:28: note: nonnull attribute specified here
#SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ~/.conan/data/#corrade/v2020.06/conan/stable/build/a588aedb50aa745a2698801b1f638aec5f70dbcd/src/#Corrade/Containers/GrowableArray.h:943:22 in
#~/.conan/data/corrade/v2020.06/conan/stable/build/#a588aedb50aa745a2698801b1f638aec5f70dbcd/src/Corrade/Containers/#GrowableArray.h:943:22: runtime error: null pointer passed as argument 2, which is #declared to never be null
#/usr/include/string.h:43:28: note: nonnull attribute specified here
#SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ~/.conan/data/#corrade/v2020.06/conan/stable/build/a588aedb50aa745a2698801b1f638aec5f70dbcd/src/#Corrade/Containers/GrowableArray.h:943:22 in
#~/.conan/data/corrade/v2020.06/conan/stable/build/#a588aedb50aa745a2698801b1f638aec5f70dbcd/src/Corrade/Containers/#GrowableArray.h:943:22: runtime error: null pointer passed as argument 2, which is #declared to never be null
#/usr/include/string.h:43:28: note: nonnull attribute specified here
#SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ~/.conan/data/#corrade/v2020.06/conan/stable/build/a588aedb50aa745a2698801b1f638aec5f70dbcd/src/#Corrade/Containers/GrowableArray.h:943:22 in
#~/.conan/data/corrade/v2020.06/conan/stable/build/#a588aedb50aa745a2698801b1f638aec5f70dbcd/src/Corrade/Containers/#GrowableArray.h:943:22: runtime error: null pointer passed as argument 2, which is #declared to never be null
#/usr/include/string.h:43:28: note: nonnull attribute specified here
#SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ~/.conan/data/#corrade/v2020.06/conan/stable/build/a588aedb50aa745a2698801b1f638aec5f70dbcd/src/#Corrade/Containers/GrowableArray.h:943:22 in
#~/.conan/data/corrade/v2020.06/conan/stable/build/#a588aedb50aa745a2698801b1f638aec5f70dbcd/src/Corrade/Containers/#GrowableArray.h:943:22: runtime error: null pointer passed as argument 2, which is #declared to never be null
#/usr/include/string.h:43:28: note: nonnull attribute specified here
#SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ~/.conan/data/#corrade/v2020.06/conan/stable/build/a588aedb50aa745a2698801b1f638aec5f70dbcd/src/#Corrade/Containers/GrowableArray.h:943:22 in

To get error build with clang and -fsanitize=address,undefined

    -DMEMORY_TOOL_REPLACES_ALLOCATOR=1
    -D_FORTIFY_SOURCE=0
    -DUNDEFINED_SANITIZER=1
    -DUNDEFINED_BEHAVIOR_SANITIZER=1
    -g -O0
    -fPIC
    -fno-optimize-sibling-calls
    -fno-omit-frame-pointer
    -fno-stack-protector
    -fno-wrapv
    -fno-sanitize-recover=all
    -fsanitize-recover=unsigned-integer-overflow
    -fsanitize=address,undefined
    -fsanitize-trap=undefined
    -fsanitize=float-divide-by-zero
    -fno-sanitize=vptr
    -fsanitize=nullability-arg
    -fsanitize=nullability-assign
    -fsanitize=nullability-return

memcpy uses __nonnull:

extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
		     size_t __n) __THROW __nonnull ((1, 2));

NOTE: -fsanitize may require instrumented libc++, see conanfile.py in https://github.com/blockspacer/llvm_tools as example how to build instrumented libc++

Possible fix:

    if(count*sizeof(T) != NULL) // take care of nonnull attribute
    {
        std::memcpy(dst, src, count*sizeof(T));
    }

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions