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 cd1a903
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 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/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 cd1a903

Please sign in to comment.