Skip to content

npb error: narrowing conversion of '-1' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Wnarrowing] #20373

Open
@fayfive

Description

Version: 29.3
Language: C++
system: Linux
g++: 9.3

I build the proto to .c and .h,I don't know if it is correct when I separate the command to generate the .c and .h

PROTOC_PATH=$(pwd)/../../../../tools/protoc
PROTO_FILES=$(pwd)/*.proto
OUTPUT_DIR=$(pwd)/../../src/proto

$PROTOC_PATH/protoc \
--plugin=protoc-gen-upb=$PROTOC_PATH/protoc-gen-upb \
--upb_out=$OUTPUT_DIR \
--proto_path=$(pwd) $PROTO_FILES

$PROTOC_PATH/protoc \
--plugin=protoc-gen-upb=$PROTOC_PATH/protoc-gen-upb_minitable \
--upb_out=$OUTPUT_DIR \
--proto_path=$(pwd) $PROTO_FILES

$PROTOC_PATH/protoc \
--plugin=protoc-gen-upb=$PROTOC_PATH/protoc-gen-upbdefs \
--upb_out=$OUTPUT_DIR \
--proto_path=$(pwd) $PROTO_FILES

Then I test the upb

 upb_Arena *arena = upb_Arena_New();
  edge_DrawProperty *draw_property = edge_DrawProperty_new(arena);
  edge_DrawProperty_set_channel_id(draw_property, 12345);
  edge_DrawProperty_set_task_id(draw_property, 67890);
  edge_Box *box = edge_DrawProperty_add_boxes(draw_property, arena);
  edge_Box_set_label(box, 1);
  edge_Box_set_x1(box, 10);
  edge_Box_set_y1(box, 20);
  edge_Box_set_x2(box, 30);
  edge_Box_set_y2(box, 40);
  edge_Box_set_score(box, 100);
  upb_Arena_Free(arena);

Then I build the cpp and it shows that

model_draw.upb_minitable.c:35:1: error: narrowing conversion of '-1' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Wnarrowing]
   35 | };
      | ^
model_draw.upb_minitable.c:55:1: error: narrowing conversion of '-1' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Wnarrowing]
   55 | };
      | ^
model_draw.upb_minitable.c:89:1: error: narrowing conversion of '-1' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Wnarrowing]
   89 | };
      | ^
model_draw.upb_minitable.c:114:1: error: narrowing conversion of '-1' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Wnarrowing]
  114 | };
      | ^
model_draw.upb_minitable.c:139:1: error: narrowing conversion of '-1' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Wnarrowing]
  139 | };
      | ^
model_draw.upb_minitable.c:195:1: error: narrowing conversion of '-1' from 'int' to 'uint8_t' {aka 'unsigned char'} [-Wnarrowing]
  195 | };

Here is .proto

syntax = "proto3";

package edge;
option go_package = "./proto/edge";

message Point {
  int32 x = 2;
  int32 y = 3;
}

message Line {
  Point p1 = 2;
  Point p2 = 3;
}

// 框出来的目标
message Box {
  int32 label = 1;
  int32 x1 = 2;
  int32 y1 = 3;
  int32 x2 = 4;
  int32 y2 = 5;
  int32 score = 6;
  repeated Roi belong_rois = 7;
}

message Roi {
  int64 id = 1;
  repeated Point points = 2;
}

message DrawCrowdProperty {
  repeated Box boxes = 1;
  repeated int64 stay_time = 2;
}

message DrawProperty {
  int64 channel_id = 1;
  int64 task_id = 2;
  repeated Box boxes = 3;
  oneof property { DrawProperty crowd = 101; }
}

here is model_draw.upb_minitable.c

/* This file was generated by upb_generator from the input file:
 *
 *     model_draw.proto
 *
 * Do not edit -- your changes will be discarded when the file is
 * regenerated.
 * NO CHECKED-IN PROTOBUF GENCODE */

#include <stddef.h>
#include "upb/generated_code_support.h"
#include "model_draw.upb_minitable.h"

// Must be last.
#include "upb/port/def.inc"

extern const struct upb_MiniTable UPB_PRIVATE(_kUpb_MiniTable_StaticallyTreeShaken);
static const upb_MiniTableField edge_Point__fields[2] = {
  {2, 8, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
  {3, 12, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
};

const upb_MiniTable edge__Point_msg_init = {
  NULL,
  &edge_Point__fields[0],
  16, 2, kUpb_ExtMode_NonExtendable, 0, UPB_FASTTABLE_MASK(24), 0,
#ifdef UPB_TRACING_ENABLED
  "edge.Point",
#endif
  UPB_FASTTABLE_INIT({
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x000800003f000010, &upb_psv4_1bt},
    {0x000c00003f000018, &upb_psv4_1bt},
  })
};

const upb_MiniTable* edge__Point_msg_init_ptr = &edge__Point_msg_init;
static const upb_MiniTableSubInternal edge_Line__submsgs[2] = {
  {.UPB_PRIVATE(submsg) = &edge__Point_msg_init_ptr},
  {.UPB_PRIVATE(submsg) = &edge__Point_msg_init_ptr},
};

static const upb_MiniTableField edge_Line__fields[2] = {
  {2, UPB_SIZE(12, 16), 64, 0, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
  {3, UPB_SIZE(16, 24), 65, 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
};

const upb_MiniTable edge__Line_msg_init = {
  &edge_Line__submsgs[0],
  &edge_Line__fields[0],
  UPB_SIZE(24, 32), 2, kUpb_ExtMode_NonExtendable, 0, UPB_FASTTABLE_MASK(255), 0,
#ifdef UPB_TRACING_ENABLED
  "edge.Line",
#endif
};

const upb_MiniTable* edge__Line_msg_init_ptr = &edge__Line_msg_init;
static const upb_MiniTableSubInternal edge_Box__submsgs[1] = {
  {.UPB_PRIVATE(submsg) = &edge__Roi_msg_init_ptr},
};

static const upb_MiniTableField edge_Box__fields[7] = {
  {1, 8, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
  {2, 12, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
  {3, 16, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
  {4, 20, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
  {5, 24, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
  {6, 28, 0, kUpb_NoSub, 5, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_4Byte << kUpb_FieldRep_Shift)},
  {7, 32, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
};

const upb_MiniTable edge__Box_msg_init = {
  &edge_Box__submsgs[0],
  &edge_Box__fields[0],
  40, 7, kUpb_ExtMode_NonExtendable, 7, UPB_FASTTABLE_MASK(56), 0,
#ifdef UPB_TRACING_ENABLED
  "edge.Box",
#endif
  UPB_FASTTABLE_INIT({
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x000800003f000008, &upb_psv4_1bt},
    {0x000c00003f000010, &upb_psv4_1bt},
    {0x001000003f000018, &upb_psv4_1bt},
    {0x001400003f000020, &upb_psv4_1bt},
    {0x001800003f000028, &upb_psv4_1bt},
    {0x001c00003f000030, &upb_psv4_1bt},
    {0x002000003f00003a, &upb_prm_1bt_max64b},
  })
};

const upb_MiniTable* edge__Box_msg_init_ptr = &edge__Box_msg_init;
static const upb_MiniTableSubInternal edge_Roi__submsgs[1] = {
  {.UPB_PRIVATE(submsg) = &edge__Point_msg_init_ptr},
};

static const upb_MiniTableField edge_Roi__fields[2] = {
  {1, UPB_SIZE(16, 8), 0, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)},
  {2, UPB_SIZE(8, 16), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
};

const upb_MiniTable edge__Roi_msg_init = {
  &edge_Roi__submsgs[0],
  &edge_Roi__fields[0],
  24, 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(24), 0,
#ifdef UPB_TRACING_ENABLED
  "edge.Roi",
#endif
  UPB_FASTTABLE_INIT({
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x000800003f000008, &upb_psv8_1bt},
    {0x001000003f000012, &upb_prm_1bt_max64b},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
  })
};

const upb_MiniTable* edge__Roi_msg_init_ptr = &edge__Roi_msg_init;
static const upb_MiniTableSubInternal edge_DrawCrowdProperty__submsgs[1] = {
  {.UPB_PRIVATE(submsg) = &edge__Box_msg_init_ptr},
};

static const upb_MiniTableField edge_DrawCrowdProperty__fields[2] = {
  {1, 8, 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
  {2, UPB_SIZE(12, 16), 0, kUpb_NoSub, 3, (int)kUpb_FieldMode_Array | (int)kUpb_LabelFlags_IsPacked | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
};

const upb_MiniTable edge__DrawCrowdProperty_msg_init = {
  &edge_DrawCrowdProperty__submsgs[0],
  &edge_DrawCrowdProperty__fields[0],
  UPB_SIZE(16, 24), 2, kUpb_ExtMode_NonExtendable, 2, UPB_FASTTABLE_MASK(24), 0,
#ifdef UPB_TRACING_ENABLED
  "edge.DrawCrowdProperty",
#endif
  UPB_FASTTABLE_INIT({
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x000800003f00000a, &upb_prm_1bt_max64b},
    {0x001000003f000012, &upb_ppv8_1bt},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
  })
};

const upb_MiniTable* edge__DrawCrowdProperty_msg_init_ptr = &edge__DrawCrowdProperty_msg_init;
static const upb_MiniTableSubInternal edge_DrawProperty__submsgs[2] = {
  {.UPB_PRIVATE(submsg) = &edge__Box_msg_init_ptr},
  {.UPB_PRIVATE(submsg) = &edge__DrawProperty_msg_init_ptr},
};

static const upb_MiniTableField edge_DrawProperty__fields[4] = {
  {1, UPB_SIZE(24, 16), 0, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)},
  {2, UPB_SIZE(32, 24), 0, kUpb_NoSub, 3, (int)kUpb_FieldMode_Scalar | ((int)kUpb_FieldRep_8Byte << kUpb_FieldRep_Shift)},
  {3, UPB_SIZE(8, 32), 0, 0, 11, (int)kUpb_FieldMode_Array | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
  {101, UPB_SIZE(16, 40), UPB_SIZE(-13, -9), 1, 11, (int)kUpb_FieldMode_Scalar | ((int)UPB_SIZE(kUpb_FieldRep_4Byte, kUpb_FieldRep_8Byte) << kUpb_FieldRep_Shift)},
};

const upb_MiniTable edge__DrawProperty_msg_init = {
  &edge_DrawProperty__submsgs[0],
  &edge_DrawProperty__fields[0],
  UPB_SIZE(40, 48), 4, kUpb_ExtMode_NonExtendable, 3, UPB_FASTTABLE_MASK(248), 0,
#ifdef UPB_TRACING_ENABLED
  "edge.DrawProperty",
#endif
  UPB_FASTTABLE_INIT({
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x001000003f000008, &upb_psv8_1bt},
    {0x001800003f000010, &upb_psv8_1bt},
    {0x002000003f00001a, &upb_prm_1bt_max64b},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x00280008650106aa, &upb_pom_2bt_max64b},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
    {0x0000000000000000, &_upb_FastDecoder_DecodeGeneric},
  })
};

const upb_MiniTable* edge__DrawProperty_msg_init_ptr = &edge__DrawProperty_msg_init;
static const upb_MiniTable *messages_layout[6] = {
  &edge__Point_msg_init,
  &edge__Line_msg_init,
  &edge__Box_msg_init,
  &edge__Roi_msg_init,
  &edge__DrawCrowdProperty_msg_init,
  &edge__DrawProperty_msg_init,
};

const upb_MiniTableFile model_draw_proto_upb_file_layout = {
  messages_layout,
  NULL,
  NULL,
  6,
  0,
  0,
};

#include "upb/port/undef.inc"

Thanks!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    untriagedauto added to all issues by default when created.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions