From: Timo Sirainen Date: Mon, 4 Oct 2021 11:22:22 +0000 (+0300) Subject: lib: container_of() - Don't check for NULL after all X-Git-Tag: 2.3.18~261 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bb5048cda0b010c2ec2166c5b8c431d5c5fc4410;p=thirdparty%2Fdovecot%2Fcore.git lib: container_of() - Don't check for NULL after all 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 --- diff --git a/src/lib/macros.h b/src/lib/macros.h index 18b32aada9..56477ead34 100644 --- a/src/lib/macros.h +++ b/src/lib/macros.h @@ -26,15 +26,9 @@ #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. */