已合并
hash key 偶现db存储乱码 #412
wangzixuan创建于 10 天前
hash key 偶现db存储乱码 #412
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 wangzixuan 的贡献)AtlasAccount
10 天前 评论:
10 天前 评论:
10 天前 添加了label:ascend-cla/yes
ascend-robot
10 天前 评论:
10 天前 评论:
Thanks for your pull-request.
The full list of commands accepted by me can be found at here。
You can get sig-info at here
PR Approval Progress
✅ Congratulations! All modules have met the lgtm and approve requirements.
Module Approval Details
| module | lgtm status | approve status |
|---|---|---|
| repo-Ascend/msprof | ✅ 潘杨杰, 陈豪, mei-feiyao (3/2) | ✅ 潘杨杰 (1/1) |
💡 Tip:
- Committer can comment
/approveor/lgtm- Commenting
/approveimplies both code review (lgtm) and intent to merge (approve)
CLA Signature Pass
Seanesmhxocism, thanks for your pull request. All authors of the commits have signed the CLA. 👍


wangzixuan
10 天前 评论:
10 天前 评论:
compile


10 天前 添加了label:ci-pipeline-running
此处折叠了41条消息 查看更多
7 天前 添加了label:lgtm
panyj1993
7 天前 评论:
7 天前 评论:
/approve


7 天前 添加了label:approved
7 天前 合入了pull request
PR 合入模板
注:经过自检不涉及的可标注“不涉及”或直接打勾,特殊情况请文字备注。不符合规范的 PR 不允许合入,请(后备)commit 注意。
1. 修改描述
目前根据初始打印,能明确存储hashDumper前数据内容均正确,但是存入db后可能存在数据问题。
void Connection::BindParameters(std::string value) // value 是按值传入的局部拷贝
{
sqlite3_bind_text(stmt_, ++index_, value.c_str(), -1, nullptr); // ← 第5参是 nullptr
}
sqlite3_bind_text 的第 5 个参数是析构函数指针,决定 SQLite 是否拷贝字符串:
nullptr == SQLITE_STATIC:告诉 SQLite 这块内存是静态的、不会被释放,SQlite 只存指针、不做拷贝
SQLITE_TRANSIENT:让 SQLite 立即做一次私有拷贝
而这里 value 是 BindParameters 的局部变量(还是按值传入的副本),函数一返回,value 就析构了,value.c_str() 指向的缓冲区就失效了。此时 SQLite 里存的 stmt 还指向这块已释放的栈/堆内存,等 sqlite3_step() 真正执行插入时,读到的就是悬垂指针指向的垃圾内容 —— 这就是乱码。
为什么偏偏是 hash_key 乱、value 看起来正常:每一行是连续两次 BindParameters(先 key 后 value),两次调用复用同一段栈帧。key 绑定后返回、内存被回收,紧接着 value 的局部 std::string 落在同一个栈地址上,导致 key 的绑定指针和 value 的绑定指针指向同一块内存。sqlite3_step 时两个字段读的是同一地址,于是 hash_key 字段显示成了 value 的内容或垃圾。这也是你上个 commit 加的那行 INFO("key is %, strKey is %, value is %", ...) 能在内存里打印出正确 key 的原因 —— 那时数据还没坏,坏在绑定之后。
把nullptr改成做一次私有拷贝
2. 功能验证
3. 分支合并要求
3. 代码检视
要求:
检视意见数:____ 条 (请填写本次检视的意见总数,用于commit合入前审视)
4. 安全自检
Python、C++
C++
5. 变更知会