Skip to content

Commit 712e038

Browse files
committed
Ensure 2-byte latin1+utf16 alignment in all cases
Resolves #59
1 parent 4e2d953 commit 712e038

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

design/mvp/canonical-abi/definitions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,31 +421,31 @@ def store_string_into_range(opts, v):
421421
match opts.string_encoding:
422422
case 'utf8':
423423
match src_simple_encoding:
424-
case 'utf8' : return store_string_copy(opts, src, src_code_units, 1, 'utf-8')
424+
case 'utf8' : return store_string_copy(opts, src, src_code_units, 1, 1, 'utf-8')
425425
case 'utf16' : return store_utf16_to_utf8(opts, src, src_code_units)
426426
case 'latin1' : return store_latin1_to_utf8(opts, src, src_code_units)
427427
case 'utf16':
428428
match src_simple_encoding:
429429
case 'utf8' : return store_utf8_to_utf16(opts, src, src_code_units)
430-
case 'utf16' : return store_string_copy(opts, src, src_code_units, 2, 'utf-16-le')
431-
case 'latin1' : return store_string_copy(opts, src, src_code_units, 2, 'utf-16-le')
430+
case 'utf16' : return store_string_copy(opts, src, src_code_units, 2, 2, 'utf-16-le')
431+
case 'latin1' : return store_string_copy(opts, src, src_code_units, 2, 2, 'utf-16-le')
432432
case 'latin1+utf16':
433433
match src_encoding:
434434
case 'utf8' : return store_string_to_latin1_or_utf16(opts, src, src_code_units)
435435
case 'utf16' : return store_string_to_latin1_or_utf16(opts, src, src_code_units)
436436
case 'latin1+utf16' :
437437
match src_simple_encoding:
438-
case 'latin1' : return store_string_copy(opts, src, src_code_units, 1, 'latin-1')
438+
case 'latin1' : return store_string_copy(opts, src, src_code_units, 1, 2, 'latin-1')
439439
case 'utf16' : return store_probably_utf16_to_latin1_or_utf16(opts, src, src_code_units)
440440

441441
#
442442

443443
MAX_STRING_BYTE_LENGTH = (1 << 31) - 1
444444

445-
def store_string_copy(opts, src, src_code_units, dst_code_unit_size, dst_encoding):
445+
def store_string_copy(opts, src, src_code_units, dst_code_unit_size, dst_alignment, dst_encoding):
446446
dst_byte_length = dst_code_unit_size * src_code_units
447447
trap_if(dst_byte_length > MAX_STRING_BYTE_LENGTH)
448-
ptr = opts.realloc(0, 0, dst_code_unit_size, dst_byte_length)
448+
ptr = opts.realloc(0, 0, dst_alignment, dst_byte_length)
449449
encoded = src.encode(dst_encoding)
450450
assert(dst_byte_length == len(encoded))
451451
opts.memory[ptr : ptr+len(encoded)] = encoded

0 commit comments

Comments
 (0)