console-server: Fix pointer arithmetic in container_of() implementation
Pointer arithmetic is performed in units of the size of the pointed-to
object. Cast to char to ensure that both the pointer arithmetic is
defined, and that subtracting the result of the offsetof() stays
in-bounds.
The issue was detected by clang-tidy:
```
>>> /usr/bin/clang-tidy --use-color -export-fixes .../obmc-console/buildc92dibdo/meson-private/clang-tidy-fix/log-handler.c.m2f5figo.yaml -quiet -p .../obmc-console/buildc92dibdo .../obmc-console/log-handler.c
9557 warnings generated.
../log-handler.c:50:9: error: suspicious usage of 'offsetof(...)' in pointer arithmetic; this scaled value will be scaled again by the '-' operator [bugprone-sizeof-expression,-warnings-as-errors]
50 | return container_of(handler, struct log_handler, handler);
| ^
../console-server.h:272:27: note: expanded from macro 'container_of'
272 | ((type *)((void *)((ptr) - offsetof(type, member))))
| ^ ~~~~~~~~~~~~~~~~~~~~~~
../log-handler.c:50:9: note: '-' in pointer arithmetic internally scales with 'sizeof(struct handler)' == 8
50 | return container_of(handler, struct log_handler, handler);
| ^
../console-server.h:272:27: note: expanded from macro 'container_of'
272 | ((type *)((void *)((ptr) - offsetof(type, member))))
| ^
```
Change-Id: I808428c0a751abeb4409cf28dd5e95588ae5c0e2
Fixes: 1a0e03b4385e ("Split IO handling code into separate handler modules")
Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
diff --git a/console-server.h b/console-server.h
index 4360513..7c45f18 100644
--- a/console-server.h
+++ b/console-server.h
@@ -269,7 +269,7 @@
#endif
#define container_of(ptr, type, member) \
- ((type *)((void *)((ptr) - offsetof(type, member))))
+ ((type *)((void *)((char *)(ptr) - offsetof(type, member))))
#define BUILD_ASSERT(c) \
do { \