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
This commit is contained in:
olly 2016-12-06 03:16:31 -08:00 committed by Oliver Woodman
parent e86bfd6dbe
commit 9ea8b02083

View file

@ -431,6 +431,9 @@ public final class ParsableByteArray {
* @return The string encoded by the bytes.
*/
public String readNullTerminatedString(int length) {
if (length == 0) {
return "";
}
int stringLength = length;
int lastIndex = position + length - 1;
if (lastIndex < limit && data[lastIndex] == 0) {