Skip to content
Snippets Groups Projects
Commit 25146985 authored by Lev Kats's avatar Lev Kats Committed by Vladimir Davydov
Browse files

trivia: use __builtin* for offsetof macro

Changed default tarantool `offsetof` macro implementation so it don't
access members of null pointer in typeof that triggers UBsan.

Needed for #10143

NO_DOC=bugfix
NO_CHANGELOG=minor
NO_TEST=tested manually with fuzzer

(cherry picked from commit 27e94824)
parent 2131743e
No related branches found
No related tags found
No related merge requests found
...@@ -626,14 +626,6 @@ sql_bind_parameter_lindex(sql_stmt * pStmt, const char *zName, ...@@ -626,14 +626,6 @@ sql_bind_parameter_lindex(sql_stmt * pStmt, const char *zName,
#define SQL_DEFAULT_COMPOUND_SELECT 30 #define SQL_DEFAULT_COMPOUND_SELECT 30
#endif #endif
/*
* GCC does not define the offsetof() macro so we'll have to do it
* ourselves.
*/
#ifndef offsetof
#define offsetof(STRUCTURE,FIELD) ((int)((char*)&((STRUCTURE*)0)->FIELD))
#endif
/* /*
* Macros to compute minimum and maximum of two numbers. * Macros to compute minimum and maximum of two numbers.
*/ */
......
...@@ -245,8 +245,12 @@ alloc_failure(const char *filename, int line, size_t size) ...@@ -245,8 +245,12 @@ alloc_failure(const char *filename, int line, size_t size)
* including padding if any. * including padding if any.
*/ */
#ifndef offsetof #ifndef offsetof
#define offsetof(type, member) ((size_t) &((type *)0)->member) # if __has_builtin(__builtin_offsetof)
#endif # define offsetof(type, member) __builtin_offsetof(type, member)
# else
# define offsetof(type, member) ((size_t)&((type *)0)->member)
# endif
#endif /* offsetof */
/** /**
* This macro is used to retrieve an enclosing structure from a pointer to * This macro is used to retrieve an enclosing structure from a pointer to
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment