Berry fix string literal

This commit is contained in:
Stephan Hadinger 2021-10-17 16:05:13 +02:00
parent 8605ad3cb8
commit 149920e363
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)