Skip to content

Commit

Permalink
fix(java): Set the default maximum value for XdrString.
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat committed Jul 12, 2023
1 parent 80e38ef commit a333318
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
4 changes: 3 additions & 1 deletion lib/xdrgen/generators/java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
module Xdrgen
module Generators

MAX_SIZE = (2 ** 31) - 1

class Java < Xdrgen::Generators::Base

def generate
Expand Down Expand Up @@ -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 ;
Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/struct.x/MyStruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion spec/output/generator_spec_java/test.x/Str2.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit a333318

Please sign in to comment.