summaryrefslogtreecommitdiff
path: root/core/variant_call.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2019-10-11 15:16:35 +0200
committerGitHub <noreply@github.com>2019-10-11 15:16:35 +0200
commitebbbcd4e160ad0cfe3f05213a9a480accd2bf627 (patch)
tree3f3d57139bec06666d967732886ed914b2c20f94 /core/variant_call.cpp
parente49b40a974d225658733a0110d8bbdafa644f236 (diff)
parent04c6579fd70ed669531113af08e45dc34ca717a9 (diff)
Merge pull request #32744 from qarmin/bytearray_compress_fix
Don't use in some functions empty PoolByteArrays
Diffstat (limited to 'core/variant_call.cpp')
-rw-r--r--core/variant_call.cpp21
1 files changed, 13 insertions, 8 deletions
diff --git a/core/variant_call.cpp b/core/variant_call.cpp
index 683c6882bf..40b944744b 100644
--- a/core/variant_call.cpp
+++ b/core/variant_call.cpp
@@ -553,7 +553,7 @@ struct _VariantCall {
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
String s;
- if (ba->size() >= 0) {
+ if (ba->size() > 0) {
PoolByteArray::Read r = ba->read();
CharString cs;
cs.resize(ba->size() + 1);
@@ -569,7 +569,7 @@ struct _VariantCall {
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
String s;
- if (ba->size() >= 0) {
+ if (ba->size() > 0) {
PoolByteArray::Read r = ba->read();
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 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));
- int result = Compression::compress(compressed.write().ptr(), ba->read().ptr(), ba->size(), mode);
-
- result = result >= 0 ? result : 0;
- compressed.resize(result);
+ compressed.resize(Compression::get_max_compressed_buffer_size(ba->size(), mode));
+ int result = Compression::compress(compressed.write().ptr(), ba->read().ptr(), ba->size(), mode);
+ result = result >= 0 ? result : 0;
+ compressed.resize(result);
+ }
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) {
PoolByteArray *ba = reinterpret_cast<PoolByteArray *>(p_self._data._mem);
+ if (ba->size() == 0) {
+ r_ret = String();
+ return;
+ }
PoolByteArray::Read r = ba->read();
String s = String::hex_encode_buffer(&r[0], ba->size());
r_ret = s;