summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRafał Mikrut <mikrutrafal54@gmail.com>2019-10-28 08:07:29 +0100
committerRafał Mikrut <mikrutrafal54@gmail.com>2019-10-28 08:07:29 +0100
commite53e1c566ac9e2e9b829f1cdbfd5d27537053cd1 (patch)
tree76cbb7b71e5da369511c6803926e33cbec858715 /core
parent4ecc30cc5ed04c770efd79c2c9f2b1dc9ae0af39 (diff)
Fix some crashes and using null pointers
Diffstat (limited to 'core')
-rw-r--r--core/crypto/hashing_context.cpp1
-rw-r--r--core/image.cpp8
-rw-r--r--core/packed_data_container.cpp1
-rw-r--r--core/translation.cpp3
4 files changed, 11 insertions, 2 deletions
diff --git a/core/crypto/hashing_context.cpp b/core/crypto/hashing_context.cpp
index bd863f546b..b5aa0ddc18 100644
--- a/core/crypto/hashing_context.cpp
+++ b/core/crypto/hashing_context.cpp
@@ -50,6 +50,7 @@ Error HashingContext::start(HashType p_type) {
Error HashingContext::update(PoolByteArray p_chunk) {
ERR_FAIL_COND_V(ctx == NULL, ERR_UNCONFIGURED);
size_t len = p_chunk.size();
+ ERR_FAIL_COND_V(len == 0, FAILED);
PoolByteArray::Read r = p_chunk.read();
switch (type) {
case HASH_MD5:
diff --git a/core/image.cpp b/core/image.cpp
index e0b0a1f8be..5e4e0c0d0c 100644
--- a/core/image.cpp
+++ b/core/image.cpp
@@ -885,8 +885,8 @@ void Image::resize(int p_width, int p_height, Interpolation p_interpolation) {
bool mipmap_aware = p_interpolation == INTERPOLATE_TRILINEAR /* || p_interpolation == INTERPOLATE_TRICUBIC */;
- ERR_FAIL_COND_MSG(p_width <= 0, "Image width cannot be greater than 0.");
- ERR_FAIL_COND_MSG(p_height <= 0, "Image height cannot be greater than 0.");
+ ERR_FAIL_COND_MSG(p_width <= 0, "Image width must be greater than 0.");
+ ERR_FAIL_COND_MSG(p_height <= 0, "Image height must be greater than 0.");
ERR_FAIL_COND_MSG(p_width > MAX_WIDTH, "Image width cannot be greater than " + itos(MAX_WIDTH) + ".");
ERR_FAIL_COND_MSG(p_height > MAX_HEIGHT, "Image height cannot be greater than " + itos(MAX_HEIGHT) + ".");
@@ -1322,6 +1322,8 @@ void Image::expand_x2_hq2x() {
PoolVector<uint8_t>::Read r = data.read();
PoolVector<uint8_t>::Write w = dest.write();
+ ERR_FAIL_COND(!r.ptr());
+
hq2x_resize((const uint32_t *)r.ptr(), width, height, (uint32_t *)w.ptr());
}
@@ -2895,6 +2897,8 @@ void Image::bumpmap_to_normalmap(float bump_scale) {
PoolVector<uint8_t>::Read rp = data.read();
PoolVector<uint8_t>::Write wp = result_image.write();
+ ERR_FAIL_COND(!rp.ptr());
+
unsigned char *write_ptr = wp.ptr();
float *read_ptr = (float *)rp.ptr();
diff --git a/core/packed_data_container.cpp b/core/packed_data_container.cpp
index 003e7e7428..7afaf7f0f1 100644
--- a/core/packed_data_container.cpp
+++ b/core/packed_data_container.cpp
@@ -137,6 +137,7 @@ uint32_t PackedDataContainer::_type_at_ofs(uint32_t p_ofs) const {
int PackedDataContainer::_size(uint32_t p_ofs) const {
PoolVector<uint8_t>::Read rd = data.read();
+ ERR_FAIL_COND_V(!rd.ptr(), 0);
const uint8_t *r = &rd[p_ofs];
uint32_t type = decode_uint32(r);
diff --git a/core/translation.cpp b/core/translation.cpp
index a0902d71fc..4a1ac26433 100644
--- a/core/translation.cpp
+++ b/core/translation.cpp
@@ -986,6 +986,7 @@ Array TranslationServer::get_loaded_locales() const {
for (const Set<Ref<Translation> >::Element *E = translations.front(); E; E = E->next()) {
const Ref<Translation> &t = E->get();
+ ERR_FAIL_COND_V(t.is_null(), Array());
String l = t->get_locale();
locales.push_back(l);
@@ -1057,6 +1058,7 @@ StringName TranslationServer::translate(const StringName &p_message) const {
for (const Set<Ref<Translation> >::Element *E = translations.front(); E; E = E->next()) {
const Ref<Translation> &t = E->get();
+ ERR_FAIL_COND_V(t.is_null(), StringName(""));
String l = t->get_locale();
if (lptr[0] != l[0] || lptr[1] != l[1])
continue; // Language code does not match.
@@ -1085,6 +1087,7 @@ StringName TranslationServer::translate(const StringName &p_message) const {
for (const Set<Ref<Translation> >::Element *E = translations.front(); E; E = E->next()) {
const Ref<Translation> &t = E->get();
+ ERR_FAIL_COND_V(t.is_null(), StringName(""));
String l = t->get_locale();
if (fptr[0] != l[0] || fptr[1] != l[1])
continue; // Language code does not match.