Skip to content
Snippets Groups Projects
Commit f09860de authored by Konstantin Belyavskiy's avatar Konstantin Belyavskiy Committed by Vladimir Davydov
Browse files

Fix compilation warning in cmp_def.h

According to offsetof(3) type of its return value is size_t.
Assigning result of offsetof() to a variable of type ptrdiff_t
may result in compilation warnings on certain platforms:

  src/box/key_def.cc:57:2: error: non-constant-expression cannot be narrowed from type 'size_t' (aka 'unsigned long') to 'ptrdiff_t' (aka 'long') in initializer list [-Wc++11-narrowing]
          OPT_DEF_ENUM(PART_OPT_TYPE, field_type, struct key_part_def, type,
          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  src/box/opt_def.h:76:19: note: expanded from macro 'OPT_DEF_ENUM'
          { key, OPT_ENUM, offsetof(opts, field), sizeof(int), #enum_name, \
                           ^~~~~~~~~~~~~~~~~~~~~
  src/trivia/util.h:193:32: note: expanded from macro 'offsetof'
  #define offsetof(type, member) ((size_t) &((type *)0)->member)
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Fix this by changing the type of opt_def::offset from ptrdiff_t to
size_t.

Closes #2930
parent 6fca090f
No related branches found
No related tags found
No related merge requests found
......@@ -57,7 +57,7 @@ typedef int64_t (*opt_def_to_enum_cb)(const char *str, uint32_t len);
struct opt_def {
const char *name;
enum opt_type type;
ptrdiff_t offset;
size_t offset;
uint32_t len;
const char *enum_name;
......
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