Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
Wrong cast in buffer allocation (fixes redis#1367)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmandalidis committed Jul 29, 2020
1 parent a731e82 commit e1d9a88
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/io/lettuce/core/codec/StringCodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void encode(String str, ByteBuf target) {
}

CharsetEncoder encoder = CharsetUtil.encoder(charset);
int length = (int) ((double) str.length() * encoder.maxBytesPerChar());
int length = str.length() * (int) encoder.maxBytesPerChar();
target.ensureWritable(length);
try {
final ByteBuffer dstBuf = target.nioBuffer(0, length);
Expand Down Expand Up @@ -165,7 +165,7 @@ private ByteBuffer encodeAndAllocateBuffer(String key) {
}

CharsetEncoder encoder = CharsetUtil.encoder(charset);
ByteBuffer buffer = ByteBuffer.allocate((int) (encoder.maxBytesPerChar() * key.length()));
ByteBuffer buffer = ByteBuffer.allocate((int) encoder.maxBytesPerChar() * key.length());

ByteBuf byteBuf = Unpooled.wrappedBuffer(buffer);
byteBuf.clear();
Expand Down

0 comments on commit e1d9a88

Please sign in to comment.