Skip to content

Commit 91400f4

Browse files
authored
Fix decoding of string length (#138)
1 parent 6f3ec0f commit 91400f4

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

tensorflow-core/tensorflow-core-api/src/main/java/org/tensorflow/internal/buffer/StringTensorBuffer.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public byte[] getObject(long index) {
105105
int length = 0;
106106
do {
107107
b = data.getByte(offset++);
108-
length |= (b & 0x7F) << pos++;
108+
length |= (b & 0x7F) << pos;
109+
pos += 7;
109110
} while ((b & 0x80) != 0);
110111

111112
// Read string of the given length

tensorflow-core/tensorflow-core-api/src/test/java/org/tensorflow/types/TStringTest.java

+13-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,19 @@ public void createScalar() {
4141
assertEquals("Pretty vacant", data.getObject());
4242
}
4343

44-
@Test
44+
@Test
45+
public void createrScalarLongerThan127() {
46+
Tensor<TString> tensor = TString.scalarOf("Long String 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 !");
47+
assertNotNull(tensor);
48+
49+
TString data = tensor.data();
50+
assertNotNull(data);
51+
assertEquals(Shape.scalar(), data.shape());
52+
assertEquals("Long String 1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 !", data.getObject());
53+
}
54+
55+
56+
@Test
4557
public void createVector() {
4658
Tensor<TString> tensor = TString.vectorOf("Pretty", "vacant");
4759
assertNotNull(tensor);

0 commit comments

Comments
 (0)