Merge pull request #2042 from jepler/qstr-expansion

makeqstrdata: permit longer "compressed" outputs
This commit is contained in:
Scott Shawcroft 2019-08-06 14:13:48 -07:00 committed by GitHub
commit 47a0b7cba1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -180,7 +180,7 @@ def compress(encoding_table, decompressed):
if not isinstance(decompressed, bytes): if not isinstance(decompressed, bytes):
raise TypeError() raise TypeError()
values, lengths = encoding_table values, lengths = encoding_table
enc = bytearray(len(decompressed)) enc = bytearray(len(decompressed) * 2)
#print(decompressed) #print(decompressed)
#print(lengths) #print(lengths)
current_bit = 7 current_bit = 7
@ -227,6 +227,8 @@ def compress(encoding_table, decompressed):
current_bit -= 1 current_bit -= 1
if current_bit != 7: if current_bit != 7:
current_byte += 1 current_byte += 1
if current_byte > len(decompressed):
print("Note: compression increased length", repr(decompressed.decode('utf-8')), len(decompressed), current_byte, file=sys.stderr)
return enc[:current_byte] return enc[:current_byte]
def qstr_escape(qst): def qstr_escape(qst):