提交 2dc91900 编写于 作者: M Megvii Engine Team

fix(fastrun/persistent_cache): fix fastrun crash

GitOrigin-RevId: b3f7bdf7dc1942a9b012f6b1575cb0a4759cb1b9
上级 a9e7a670
......@@ -176,11 +176,9 @@ AlgoChooserProfileCache::get(const Key &key) {
auto entry_len = read_uint32();
mgb_assert(buf + entry_len <= buf_end);
int rep;
auto nr = sscanf(reinterpret_cast<const char*>(buf), ENTRY_FMT,
&rep, &i.time, &i.workspace);
&i.reproducible, &i.time, &i.workspace);
mgb_assert(nr == 3);
i.reproducible = rep;
buf += entry_len;
}
mgb_assert(buf == buf_end);
......@@ -228,6 +226,8 @@ void AlgoChooserProfileCache::put(const Key &key, Result &result) {
val.resize(pos + SPR_SIZE);
uint32_t nr = snprintf(&val[pos], SPR_SIZE,
ENTRY_FMT, i.reproducible, i.time, i.workspace);
//! for memory boundary failed, snprintf ret do not contain \0
nr += 1;
mgb_assert(nr < SPR_SIZE);
memcpy(&val[pos - sizeof(uint32_t)], &nr, sizeof(nr));
val.resize(pos + nr);
......
......@@ -100,7 +100,8 @@ namespace mgb {
struct ResultEntry {
std::string algo; //! identifier of the algorithm
bool reproducible; //! whether algorithm is reproducible
//! sscanf will up bool as int
int reproducible; //! whether algorithm is reproducible
double time; //! execution time in seconds
size_t workspace; //! workspace in bytes
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册