Merge pull request #32744 from qarmin/bytearray_compress_fix
Don't use in some functions empty PoolByteArrays
This commit is contained in:
commit
ebbbcd4e16
1 changed files with 13 additions and 8 deletions
|
@ -553,7 +553,7 @@ struct _VariantCall {
|
||||||
|
|
||||||
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
||||||
String s;
|
String s;
|
||||||
if (ba->size() >= 0) {
|
if (ba->size() > 0) {
|
||||||
PoolByteArray::Read r = ba->read();
|
PoolByteArray::Read r = ba->read();
|
||||||
CharString cs;
|
CharString cs;
|
||||||
cs.resize(ba->size() + 1);
|
cs.resize(ba->size() + 1);
|
||||||
|
@ -569,7 +569,7 @@ struct _VariantCall {
|
||||||
|
|
||||||
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
||||||
String s;
|
String s;
|
||||||
if (ba->size() >= 0) {
|
if (ba->size() > 0) {
|
||||||
PoolByteArray::Read r = ba->read();
|
PoolByteArray::Read r = ba->read();
|
||||||
s.parse_utf8((const char *)r.ptr(), ba->size());
|
s.parse_utf8((const char *)r.ptr(), ba->size());
|
||||||
}
|
}
|
||||||
|
@ -580,14 +580,15 @@ struct _VariantCall {
|
||||||
|
|
||||||
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
||||||
PoolByteArray compressed;
|
PoolByteArray compressed;
|
||||||
Compression::Mode mode = (Compression::Mode)(int)(*p_args[0]);
|
if (ba->size() > 0) {
|
||||||
|
Compression::Mode mode = (Compression::Mode)(int)(*p_args[0]);
|
||||||
|
|
||||||
compressed.resize(Compression::get_max_compressed_buffer_size(ba->size(), mode));
|
compressed.resize(Compression::get_max_compressed_buffer_size(ba->size(), mode));
|
||||||
int result = Compression::compress(compressed.write().ptr(), ba->read().ptr(), ba->size(), mode);
|
int result = Compression::compress(compressed.write().ptr(), ba->read().ptr(), ba->size(), mode);
|
||||||
|
|
||||||
result = result >= 0 ? result : 0;
|
|
||||||
compressed.resize(result);
|
|
||||||
|
|
||||||
|
result = result >= 0 ? result : 0;
|
||||||
|
compressed.resize(result);
|
||||||
|
}
|
||||||
r_ret = compressed;
|
r_ret = compressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -615,6 +616,10 @@ struct _VariantCall {
|
||||||
|
|
||||||
static void _call_PoolByteArray_hex_encode(Variant &r_ret, Variant &p_self, const Variant **p_args) {
|
static void _call_PoolByteArray_hex_encode(Variant &r_ret, Variant &p_self, const Variant **p_args) {
|
||||||
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
|
||||||
|
if (ba->size() == 0) {
|
||||||
|
r_ret = String();
|
||||||
|
return;
|
||||||
|
}
|
||||||
PoolByteArray::Read r = ba->read();
|
PoolByteArray::Read r = ba->read();
|
||||||
String s = String::hex_encode_buffer(&r[0], ba->size());
|
String s = String::hex_encode_buffer(&r[0], ba->size());
|
||||||
r_ret = s;
|
r_ret = s;
|
||||||
|
|
Loading…
Reference in a new issue