]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: container_of() - Don't check for NULL after all
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Mon, 4 Oct 2021 11:22:22 +0000 (14:22 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 5 Oct 2021 09:57:30 +0000 (09:57 +0000)
Adding the explicit NULL checks for container_of() caused caused static
analyzers to think that NULL could be returned at any time. This caused
unnecessary warnings in various places.

Reverts b178d0792b6335277f7fa831fd7e5403105abd04

src/lib/macros.h

index 18b32aada9f645185a9817b311ed93419e799d4c..56477ead3474f352597e4e2e0e8e2eee6e475e54 100644 (file)
 #define CONST_PTR_OFFSET(ptr, offset) \
        ((const void *) (((uintptr_t) (ptr)) + ((size_t) (offset))))
 
-static inline const char *container_of_ptr(const void *ptr, size_t offset)
-{
-       if (ptr == NULL)
-               return NULL;
-       return (const char *)ptr - offset;
-}
 #define container_of(ptr, type, name) \
-       (type *)(container_of_ptr(ptr, offsetof(type, name) + \
-                COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE(ptr, &((type *) 0)->name)))
+       (type *)((char *)(ptr) - offsetof(type, name) + \
+                COMPILE_ERROR_IF_TYPES_NOT_COMPATIBLE(ptr, &((type *) 0)->name))
 
 /* Don't use simply MIN/MAX, as they're often defined elsewhere in include
    files that are included after this file generating tons of warnings. */