msoucy / dproto

D Protocol Buffer mixins to create structures at compile time
Boost Software License 1.0
37 stars 16 forks source link

BUG:Conversion positive overflow for negative integers (works in C++, fails in D) #115

Closed timotheecour closed 6 years ago

timotheecour commented 7 years ago

@msoucy seems like a serious bug; currently a blocker:

/+
D20170610T004601:here
std.conv.ConvOverflowException@dmd2_072_2/linux/bin64/../../src/phobos/std/conv.d(1350): Conversion positive overflow

dmd2_072_2/linux/bin64/../../src/phobos/std/conv.d:143 pure @safe int std.conv.toImpl!(int, ulong).toImpl(ulong) [0x5b0375]
dmd2_072_2/linux/bin64/../../src/phobos/std/conv.d:183 pure @safe int std.conv.to!(int).to!(ulong).to(ulong) [0x5b0318]
~/.dub/packages/dproto-2.1.3/dproto/import/dproto/serialize.d:399 pure @safe int dproto.serialize.readProto!("int32", ubyte[]).readProto(ref ubyte[]) [0x60c3a8]
~/.dub/packages/dproto-2.1.3/dproto/import/dproto/attributes.d:210 pure @safe void dproto.attributes.putSingleProtoVal!("int32", int, ubyte[]).putSingleProtoVal(ref int, ref ubyte[]) [0x60c374]
~/.dub/packages/dproto-2.1.3/dproto/import/dproto/attributes.d:197 [0x62eae4]
~/.dub/packages/dproto-2.1.3/dproto/import/dproto/attributes.d:88 [0x62ea65]
~/.dub/packages/dproto-2.1.3/dproto/import/dproto/attributes.d:52 [0x62e9bf]
bug.d:30 [0x62e884]
+/

import dproto.dproto;
mixin ProtocolBufferFromString!(`
message Foo{
  optional int32 y = 1;// BUG:Conversion positive overflow
  //repeated int32 x = 1 [ packed = true ];// ditto
  //repeated int64 x = 1 [ packed = true ]; // ditto
  //repeated int32 x = 1; //ditto

  //repeated sint32 x = 1 [ packed = true ]; //ok
  //repeated sfixed32 x = 1 [ packed = true ];//ok
  //repeated uint32 x = 1 [ packed = true ]; //works but should it?
  //repeated fixed32 x = 1 [ packed = true ];//ok but should it?
}

`);

void main(){
  Foo a;
  a.y=-3;
  //a.x=[-3];
  auto s=a.serialize;
  auto a2=Foo(s);  // crash here
  assert(a==a2);
}

EDIT: happens also w latest git master: 7a73ae7329a58feec14a2b8d4f13ad7c59207ce1 EDIT: found how to fix; will submit a PR

timotheecour commented 7 years ago

see PR to fix this in https://github.com/msoucy/dproto/pull/116 curious how this bug went unnoticed until now...

heketang commented 7 years ago

Only a small number of users

timotheecour commented 6 years ago

closing via https://github.com/msoucy/dproto/pull/131