diff --git a/src/core/impl/utils/persistent_cache.cpp b/src/core/impl/utils/persistent_cache.cpp index 75996a24..ec6651e8 100644 --- a/src/core/impl/utils/persistent_cache.cpp +++ b/src/core/impl/utils/persistent_cache.cpp @@ -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(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); diff --git a/src/core/include/megbrain/utils/persistent_cache.h b/src/core/include/megbrain/utils/persistent_cache.h index bd6ce5a2..5ad1f80b 100644 --- a/src/core/include/megbrain/utils/persistent_cache.h +++ b/src/core/include/megbrain/utils/persistent_cache.h @@ -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 };