-
Notifications
You must be signed in to change notification settings - Fork 282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
修复bug:在MSVC debug环境下,直接value解引用会触发cannot access empty value optional断… #185
修复bug:在MSVC debug环境下,直接value解引用会触发cannot access empty value optional断… #185
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## master #185 +/- ##
==========================================
+ Coverage 46.01% 46.06% +0.04%
==========================================
Files 22 22
Lines 3260 3263 +3
==========================================
+ Hits 1500 1503 +3
Misses 1760 1760 ☔ View full report in Codecov by Sentry. |
ormpp/mysql.hpp
Outdated
using value_type = typename U::value_type; | ||
value = value_type(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这样改好点:
if(!value.has_value()) {
value = value_type{};
}
只在没有初始化的时候才给默认值。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已按照修改意见修改
能加一个测试吗,把这个分支的代码覆盖到。 |
我看了一下,这个修改只对mysql.hpp之下的query和query_s函数有影响,然后主要是针对std::optional类型的查询的修改。原来的测试集中已经有了对std::optional的查询测试TEST_CASE("optional"),能够覆盖本次修改。但是我发现测试中只有query的没有写query_s的。我添加了query_s相关的测试 |
我的意思是之前会crash说明没测试到,现在用之前crash的case 测试是不是不会再有问题了? 另外,根据ci的提示修改一下代码格式。 |
我本地跑了测试集了,这个修改没有问题了。格式也用clang-format重新刷了 |
…言,导致程序崩溃。
在下面的语句中value其实是一个std::optional,
set_param_bind(param_bind, *value, i, mp, is_null);
直接*value解引用会触发下述语句
由于debug环境下_STL_VERIFY(this->_Has_value, "Cannot access value of empty optional");断言命中程序崩溃。解决方法是在解引用之前给std::optional的value先提供一个默认值。确保断言不会触发