Merge pull request #13393 from s-hadinger/berry_fix_bytes_literal

Berry fix bytes literal
This commit is contained in:
s-hadinger 2021-10-17 16:20:19 +02:00 committed by GitHub
commit d58af22bf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 5 deletions

View File

@ -579,11 +579,14 @@ static int m_init(bvm *vm)
if (hex_in) { if (hex_in) {
size_arg = strlen(hex_in) / 2; /* allocate headroom */ size_arg = strlen(hex_in) / 2; /* allocate headroom */
} }
} /* check if fixed size that we have the right size */
if (size_arg > attr.size) {
/* check if fixed size that we have the right size */ if (attr.fixed) {
if (attr.fixed && size_arg > attr.size) { be_raise(vm, BYTES_RESIZE_ERROR, BYTES_RESIZE_MESSAGE);
be_raise(vm, BYTES_RESIZE_ERROR, BYTES_RESIZE_MESSAGE); } else {
attr.size = size_arg;
}
}
} }
/* allocate */ /* allocate */

View File

@ -7,6 +7,8 @@ b=bytes(0)
assert(str(b) == "bytes('')") assert(str(b) == "bytes('')")
b=bytes(1) b=bytes(1)
assert(str(b) == "bytes('')") assert(str(b) == "bytes('')")
b=bytes(-1)
assert(str(b) == "bytes('')")
assert(b.size() == 0) assert(b.size() == 0)
b=bytes("a") b=bytes("a")
@ -164,3 +166,5 @@ b=bytes()
b.fromstring("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.") b.fromstring("Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.")
assert(str(b) =="bytes('4C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E73...')") assert(str(b) =="bytes('4C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E73...')")
assert(b.tostring(0) =="bytes('4C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E73656374657475722061646970697363696E6720656C69742C2073656420646F20656975736D6F642074656D706F7220696E6369646964756E74207574206C61626F726520657420646F6C6F7265206D61676E6120616C697175612E')") assert(b.tostring(0) =="bytes('4C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E73656374657475722061646970697363696E6720656C69742C2073656420646F20656975736D6F642074656D706F7220696E6369646964756E74207574206C61626F726520657420646F6C6F7265206D61676E6120616C697175612E')")
assert(size(bytes('4C6F72656D20697073756D20646F6C6F722073697420616D65742C20636F6E73656374657475722061646970697363696E6720656C69742C2073656420646F20656975736D6F642074656D706F7220696E6369646964756E74207574206C61626F726520657420646F6C6F7265206D61676E6120616C697175612E')) == 123)