mirror of https://github.com/arendst/Tasmota.git
Berry `bytes.resize()` for large sizes (#21716)
This commit is contained in:
parent
c8e29dafc6
commit
b6c488a883
|
@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
|
|||
- ESP32 TM1621 number overflow from "9999" to "12E3" (#21131)
|
||||
|
||||
### Fixed
|
||||
- Berry `bytes.resize()` for large sizes
|
||||
|
||||
### Removed
|
||||
|
||||
|
|
|
@ -223,7 +223,7 @@ static unsigned int decode_base64(unsigned char input[], unsigned char output[])
|
|||
// shrink or increase. If increase, fill with zeores. Cannot go beyond `size`
|
||||
static void buf_set_len(buf_impl* attr, const size_t len)
|
||||
{
|
||||
uint16_t old_len = attr->len;
|
||||
int32_t old_len = attr->len;
|
||||
attr->len = ((int32_t)len <= attr->size) ? (int32_t)len : attr->size;
|
||||
if (old_len < attr->len) {
|
||||
memset((void*) &attr->bufptr[old_len], 0, attr->len - old_len);
|
||||
|
|
|
@ -79,15 +79,17 @@ static int i_readbytes(bvm *vm)
|
|||
be_call(vm, 2); /* call b.resize(size) */
|
||||
be_pop(vm, 3); /* bytes() instance is at top */
|
||||
|
||||
char *buffer = (char*) be_tobytes(vm, -1, NULL); /* we get the address of the internam buffer of size 'size' */
|
||||
size = be_fread(fh, buffer, size);
|
||||
char *buffer = (char*) be_tobytes(vm, -1, NULL); /* we get the address of the internal buffer of size 'size' */
|
||||
size_t read_size = be_fread(fh, buffer, size);
|
||||
|
||||
/* resize if something went wrong */
|
||||
be_getmember(vm, -1, "resize");
|
||||
be_pushvalue(vm, -2);
|
||||
be_pushint(vm, size);
|
||||
be_call(vm, 2); /* call b.resize(size) */
|
||||
be_pop(vm, 3); /* bytes() instance is at top */
|
||||
if (size != read_size) {
|
||||
/* resize if something went wrong */
|
||||
be_getmember(vm, -1, "resize");
|
||||
be_pushvalue(vm, -2);
|
||||
be_pushint(vm, read_size);
|
||||
be_call(vm, 2); /* call b.resize(size) */
|
||||
be_pop(vm, 3); /* bytes() instance is at top */
|
||||
}
|
||||
} else {
|
||||
be_pushbytes(vm, NULL, 0);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue