forked from OSSInnovation/mindspore
!6613 Fix core dump in pynative mode
Merge pull request !6613 from huangbingjian/master
This commit is contained in:
commit
806a34116d
|
@ -100,28 +100,27 @@ bool ProcessInner(const std::string &message, const int &bias, uint32_t *digest,
|
|||
w[i] = sigma3(w[i - 2]) + w[i - 7] + sigma2(w[i - 15]) + w[i - 16];
|
||||
}
|
||||
|
||||
std::shared_ptr<uint32_t> hash(new uint32_t[digest_size], std::default_delete<uint32_t[]>());
|
||||
std::shared_ptr<uint32_t[]> hash(new uint32_t[digest_size]());
|
||||
size_t mem_size = digest_size * sizeof(uint32_t);
|
||||
auto ret = memcpy_s(hash.get(), mem_size, digest, mem_size);
|
||||
if (ret != EOK) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < kIterationNumber; ++i) {
|
||||
uint32_t t1 =
|
||||
w[i] + constant[i] + hash.get()[7] + sigma1(hash.get()[4]) + ch(hash.get()[4], hash.get()[5], hash.get()[6]);
|
||||
uint32_t t2 = sigma0(hash.get()[0]) + ma(hash.get()[0], hash.get()[1], hash.get()[2]);
|
||||
uint32_t t1 = w[i] + constant[i] + hash[7] + sigma1(hash[4]) + ch(hash[4], hash[5], hash[6]);
|
||||
uint32_t t2 = sigma0(hash[0]) + ma(hash[0], hash[1], hash[2]);
|
||||
for (int j = digest_size - 1; j >= 0; --j) {
|
||||
if (j == 4) {
|
||||
hash.get()[j] = hash.get()[j - 1] + t1;
|
||||
hash[j] = hash[j - 1] + t1;
|
||||
} else if (j == 0) {
|
||||
hash.get()[j] = t1 + t2;
|
||||
hash[j] = t1 + t2;
|
||||
} else {
|
||||
hash.get()[j] = hash.get()[j - 1];
|
||||
hash[j] = hash[j - 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < digest_size; ++i) {
|
||||
digest[i] += hash.get()[i];
|
||||
digest[i] += hash[i];
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@
|
|||
#include <algorithm>
|
||||
#include <type_traits>
|
||||
#include <typeinfo>
|
||||
#include <regex>
|
||||
|
||||
#include "abstract/abstract_value.h"
|
||||
|
||||
|
@ -373,25 +372,17 @@ class TensorDataImpl : public TensorData {
|
|||
std::is_same<T, double>::value) {
|
||||
return str;
|
||||
}
|
||||
// Use regular expressions to replace placeholders.
|
||||
std::regex pattern("#+");
|
||||
std::smatch result;
|
||||
int bias = 0;
|
||||
std::string::const_iterator start = str.begin();
|
||||
std::string::const_iterator end = str.end();
|
||||
while (std::regex_search(start, end, result, pattern)) {
|
||||
const int len = result.str(0).length();
|
||||
const int pos = result.position();
|
||||
bias += pos;
|
||||
if (bias > static_cast<int32_t>(str.length())) {
|
||||
return "";
|
||||
// Replace # with placeholder.
|
||||
size_t index = str.find('#');
|
||||
while (index != str.npos) {
|
||||
size_t pos = index;
|
||||
while (str[pos] == '#') {
|
||||
pos++;
|
||||
}
|
||||
// Replace # with placeholder.
|
||||
int len = pos - index;
|
||||
std::string space(max_width - len, ' ');
|
||||
str = str.replace(bias, len, space);
|
||||
// Update the starting position of the search.
|
||||
start = str.begin() + bias;
|
||||
end = str.end();
|
||||
str = str.replace(index, len, space);
|
||||
index = str.find('#', index);
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue