Skip to content

Comply with -Wconversion strict gcc setting #8062

@greenrobot

Description

@greenrobot

Disclaimer why this matters: (very) strict compiler settings are often required in mission critical projects.

"Regression" introduced in aeba096 adds a new strict compiler violation in gcc.

flatbuffers/flatbuffers/flatbuffer_builder.h:48:23: error: conversion from 'long unsigned int' to 'flatbuffers::voffset_t' {aka 'short unsigned int'} may change value [-Werror=conversion]
   48 |   return fixed_fields + field_id * sizeof(voffset_t);
      |          ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Causing code is still present in today's master branch:

// Converts a Field ID to a virtual table offset.
inline voffset_t FieldIndexToOffset(voffset_t field_id) {
  // Should correspond to what EndTable() below builds up.
  const voffset_t fixed_fields =
      2 * sizeof(voffset_t);  // Vtable size and Object Size.
  return fixed_fields + field_id * sizeof(voffset_t);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions