Commit 9ea8b020 by olly Committed by Oliver Woodman

Correctly handle reading of an empty string without a terminating NUL byte

Issue: #2152

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=141159330
parent e86bfd6d
...@@ -431,6 +431,9 @@ public final class ParsableByteArray { ...@@ -431,6 +431,9 @@ public final class ParsableByteArray {
* @return The string encoded by the bytes. * @return The string encoded by the bytes.
*/ */
public String readNullTerminatedString(int length) { public String readNullTerminatedString(int length) {
if (length == 0) {
return "";
}
int stringLength = length; int stringLength = length;
int lastIndex = position + length - 1; int lastIndex = position + length - 1;
if (lastIndex < limit && data[lastIndex] == 0) { if (lastIndex < limit && data[lastIndex] == 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment