mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-22 02:06:31 +00:00
Berry 'bytes().asstring()' now truncates a string if buffer contains NULL (#23311)
This commit is contained in:
parent
2bc5f682b0
commit
c2628c95f3
@ -12,6 +12,7 @@ All notable changes to this project will be documented in this file.
|
||||
### Changed
|
||||
|
||||
### Fixed
|
||||
- Berry `bytes().asstring()` now truncates a string if buffer contains NULL
|
||||
|
||||
### Removed
|
||||
|
||||
|
@ -806,7 +806,8 @@ static int m_asstring(bvm *vm)
|
||||
{
|
||||
buf_impl attr = bytes_check_data(vm, 0);
|
||||
check_ptr(vm, &attr);
|
||||
be_pushnstring(vm, (const char*) attr.bufptr, attr.len);
|
||||
size_t safe_len = strnlen((const char*) attr.bufptr, attr.len);
|
||||
be_pushnstring(vm, (const char*) attr.bufptr, safe_len);
|
||||
be_return(vm);
|
||||
}
|
||||
|
||||
|
@ -354,3 +354,9 @@ assert(b.appendb64(c, 2) == bytes("AABBCC49673D3D"))
|
||||
b = bytes("AABBCC")
|
||||
assert(bytes().fromstring(bytes("11").tob64()) == bytes('45513D3D'))
|
||||
assert(b.appendb64(c, 1, 1) == bytes("AABBCC45513D3D"))
|
||||
|
||||
#- asstring truncates if NULL is present -#
|
||||
s=bytes("414243").asstring()
|
||||
assert(size(s) == 3)
|
||||
s=bytes("410000").asstring()
|
||||
assert(size(s) == 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user