Merge pull request #8 in MM/mpin-sdk-core from bugfix/MAASMOB-40 to master
* commit 'c7805ec4576b5d70e46a4e450abd12a06780c440':
Protect from failed allocations
diff --git a/src/mpin_crypto_non_tee.cpp b/src/mpin_crypto_non_tee.cpp
index 77cdbc0..ebc991c 100644
--- a/src/mpin_crypto_non_tee.cpp
+++ b/src/mpin_crypto_non_tee.cpp
@@ -42,18 +42,27 @@
Octet::Octet(size_t maxSize)
{
- this->max = maxSize;
+ this->max = 0;
this->len = 0;
this->val = (char *) calloc(maxSize, 1);
+ if(this->val != NULL)
+ {
+ this->max = maxSize;
+ }
}
Octet::Octet(const String& str)
{
+ this->max = 0;
+ this->len = 0;
size_t maxSize = str.size();
- this->max = maxSize;
- this->len = maxSize;
this->val = (char *) malloc(maxSize);
- memcpy(this->val, str.c_str(), maxSize);
+ if(this->val != NULL)
+ {
+ this->max = maxSize;
+ this->len = maxSize;
+ memcpy(this->val, str.c_str(), maxSize);
+ }
}
Octet::~Octet()