From a333318ea4044b5deeefe65958f4e97ae2c065cc Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Wed, 12 Jul 2023 18:06:23 +0800 Subject: [PATCH 1/2] fix(java): Set the default maximum value for XdrString. --- lib/xdrgen/generators/java.rb | 4 +++- spec/output/generator_spec_java/struct.x/MyStruct.java | 2 +- spec/output/generator_spec_java/test.x/Str2.java | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/xdrgen/generators/java.rb b/lib/xdrgen/generators/java.rb index 476c1d754..2fea98f3c 100644 --- a/lib/xdrgen/generators/java.rb +++ b/lib/xdrgen/generators/java.rb @@ -3,6 +3,8 @@ module Xdrgen module Generators + MAX_SIZE = (2 ** 31) - 1 + class Java < Xdrgen::Generators::Base def generate @@ -807,7 +809,7 @@ def decode_type(decl) when AST::Typespecs::Bool ; "stream.readInt() == 1 ? true : false" when AST::Typespecs::String ; - "XdrString.decode(stream, #{decl.size})" + "XdrString.decode(stream, #{decl.size || MAX_SIZE})" when AST::Typespecs::Simple ; "#{name decl.type.resolved_type}.decode(stream)" when AST::Concerns::NestedDefinition ; diff --git a/spec/output/generator_spec_java/struct.x/MyStruct.java b/spec/output/generator_spec_java/struct.x/MyStruct.java index 69cde5e57..e55cf60fb 100644 --- a/spec/output/generator_spec_java/struct.x/MyStruct.java +++ b/spec/output/generator_spec_java/struct.x/MyStruct.java @@ -76,7 +76,7 @@ public static MyStruct decode(XdrDataInputStream stream) throws IOException { int someOpaquesize = 10; decodedMyStruct.someOpaque = new byte[someOpaquesize]; stream.read(decodedMyStruct.someOpaque, 0, someOpaquesize); - decodedMyStruct.someString = XdrString.decode(stream, ); + decodedMyStruct.someString = XdrString.decode(stream, 2147483647); decodedMyStruct.maxString = XdrString.decode(stream, 100); return decodedMyStruct; } diff --git a/spec/output/generator_spec_java/test.x/Str2.java b/spec/output/generator_spec_java/test.x/Str2.java index a3a3a6658..182bf8d62 100644 --- a/spec/output/generator_spec_java/test.x/Str2.java +++ b/spec/output/generator_spec_java/test.x/Str2.java @@ -39,7 +39,7 @@ public void encode(XdrDataOutputStream stream) throws IOException { } public static Str2 decode(XdrDataInputStream stream) throws IOException { Str2 decodedStr2 = new Str2(); - decodedStr2.str2 = XdrString.decode(stream, ); + decodedStr2.str2 = XdrString.decode(stream, 2147483647); return decodedStr2; } From 42cb4d4950276d14986a470db34511143158670a Mon Sep 17 00:00:00 2001 From: overcat <4catcode@gmail.com> Date: Thu, 10 Aug 2023 09:23:05 +0800 Subject: [PATCH 2/2] improve --- lib/xdrgen/generators/java.rb | 5 +---- spec/output/generator_spec_java/struct.x/MyStruct.java | 2 +- spec/output/generator_spec_java/test.x/Str2.java | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/xdrgen/generators/java.rb b/lib/xdrgen/generators/java.rb index c8b4a04b9..20f59ec62 100644 --- a/lib/xdrgen/generators/java.rb +++ b/lib/xdrgen/generators/java.rb @@ -2,9 +2,6 @@ module Xdrgen module Generators - - MAX_SIZE = (2 ** 31) - 1 - class Java < Xdrgen::Generators::Base def generate @@ -836,7 +833,7 @@ def decode_type(decl) when AST::Typespecs::Bool ; "stream.readInt() == 1 ? true : false" when AST::Typespecs::String ; - "XdrString.decode(stream, #{decl.size || MAX_SIZE})" + "XdrString.decode(stream, #{decl.size || 'Integer.MAX_VALUE'})" when AST::Typespecs::Simple ; "#{name decl.type.resolved_type}.decode(stream)" when AST::Concerns::NestedDefinition ; diff --git a/spec/output/generator_spec_java/struct.x/MyStruct.java b/spec/output/generator_spec_java/struct.x/MyStruct.java index 35a682b45..9fb7496c7 100644 --- a/spec/output/generator_spec_java/struct.x/MyStruct.java +++ b/spec/output/generator_spec_java/struct.x/MyStruct.java @@ -76,7 +76,7 @@ public static MyStruct decode(XdrDataInputStream stream) throws IOException { int someOpaquesize = 10; decodedMyStruct.someOpaque = new byte[someOpaquesize]; stream.read(decodedMyStruct.someOpaque, 0, someOpaquesize); - decodedMyStruct.someString = XdrString.decode(stream, 2147483647); + decodedMyStruct.someString = XdrString.decode(stream, Integer.MAX_VALUE); decodedMyStruct.maxString = XdrString.decode(stream, 100); return decodedMyStruct; } diff --git a/spec/output/generator_spec_java/test.x/Str2.java b/spec/output/generator_spec_java/test.x/Str2.java index 0f7036b0e..12bfdad3d 100644 --- a/spec/output/generator_spec_java/test.x/Str2.java +++ b/spec/output/generator_spec_java/test.x/Str2.java @@ -39,7 +39,7 @@ public void encode(XdrDataOutputStream stream) throws IOException { } public static Str2 decode(XdrDataInputStream stream) throws IOException { Str2 decodedStr2 = new Str2(); - decodedStr2.str2 = XdrString.decode(stream, 2147483647); + decodedStr2.str2 = XdrString.decode(stream, Integer.MAX_VALUE); return decodedStr2; }