- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我需要解决一个编译器发现的错误——我理解为什么它会发现那个错误但需要解决它因为函数(抛出错误)只会在指针是 已初始化。
这是我的伪代码:
if (incoming_message_exists)
{
msg_class* current_msg;
/*current_msg will become either value_1 or value_2*/
/*code block 1*/
if (condition_is_fulfilled)
{
current_msg = value_1;
}
/*code block 2*/
else
{
current_msg = value_2;
}
/*code block 3*/
/*bool function performed on current_msg that is throwing error*/
if (function(current_msg))
{
//carry out function
}
}
我不希望在 1 和 2 中执行代码块 3,但如果这是唯一的解决方案,那么我会这样做。提前致谢!
最佳答案
您向我们展示的 if
和 else
分支是否来自两个不同的 if
语句?
如果是,则您当前的代码能够使 current_msg
未初始化。当您到达 function(current_msg)
时,这可能会崩溃。
如果您向我们展示了同一 if
语句的两个分支,则您的编译器是错误的 - 没有 current_msg
未被初始化的危险。但是,您可能仍需要更改代码以抑制警告,例如如果您将警告作为错误进行构建。
您可以通过在声明时初始化 current_msg
来修复/抑制警告
msg_class* current_msg = NULL;
如果您在任何一个分支中都没有其他代码,您也可以使用三元运算符进行初始化
msg_class* current_msg = condition_is_fulfilled? value_1 : value_2;
如果警告是真实的,您还必须检查 function
是否处理传递给 NULL
参数或防止这种情况
if (current_msg != NULL && function(current_msg))
关于c++ - 解决编译器错误 : pointer potentially uninitialized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16666734/
即使图中没有循环,BGL 的 depth_first_search 算法有时也会对访问者调用 back_edge()。根据后边缘的定义,以及根据 Boost 的 DFS Visitor Documen
所以,我有一个可以从大约四个不同函数调用的例程。我想要做的是遍历可能调用此例程的路线。 我正在使用 Eclipse。我认为这一定是有可能的,因为我知道我可以手动完成此操作,尽管速度很慢。 最佳答案 在
Xcode 的分析器提示存在“对象的潜在泄漏”。以下方法中的第一行被突出显示: - (void)retrieveBeginRestoreData { self.restoreContext =
我目前正在扩展 lavalamp plugin在下拉菜单上工作,但我遇到了一个小问题。我需要知道隐藏元素的 offsetWidth。现在显然这个问题没有意义,而我正在寻找的是元素的 offsetWid
在“窗口”>“首选项”>“常规”>“搜索”下,有“忽略潜在匹配项”选项 它有什么作用?无论我是否激活它,我都看不出有什么区别。 它是一个仅对 Java 开发有意义的选项(我从不这样做,但我确实使用 E
当我运行以下函数时,出现此错误: “错误:潜在的无限循环。” 问题似乎是我在拼接方法中使用的“0”,因为当我将其更改为任何其他数字(1 - 9)时,我不会收到此错误。 我不确定这将如何创建无限循环。
我有一个 Web API 项目。我的端点之一允许进行字符串搜索,其中可能包含特殊字符。 [RoutePrefix("api/Search")] [ValidateInput(false)] // th
嗨, 我运行了 XCode 分析器 - 它告诉我以下两者都是潜在的内存泄漏。我不知道为什么。我像这样声明了 midiDevices @property (assign, nonatomic) NSMu
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: A potentially dangerous Request.Form value was detected fr
我需要解决一个编译器发现的错误——我理解为什么它会发现那个错误但需要解决它因为函数(抛出错误)只会在指针是 已初始化。 这是我的伪代码: if (incoming_message_exists) {
在调用 isDataMatchingnamespace 时,我得到了 this 的潜在无效用法如何克服以及如何以正确的方式调用 isDataMatchingnamespace? function Cl
documentation for the Cwd module声明 fast_abs_path是“更危险但可能更快的 abs_path 版本”。它以什么方式危险?什么情况下比较快?行为是否因平台而异
MSVC 对潜在未初始化变量的警告并不是特别好,特别是它错误地声称 i 可以在此程序中未初始化: #include enum class Color{ Red, Green }; in
我的实体 Item 有一个存储库 (ItemRepository),函数为 findItemCount()。当我使用 $repository = $em->getRepository(Item::cl
我的实体 Item 有一个存储库 (ItemRepository),函数为 findItemCount()。当我使用 $repository = $em->getRepository(Item::cl
我的 Eclipse 发出以下警告: Potential resource leak: '' may not be closed ...对于表达式 new BufferedWriter(...)在下面
您认为解决以下问题时的最佳实践是: MyClass myVariable = null; if ( ..condition 1.. ) { myVariable = new MyClass(1);
创建 Funds 时或 Assets表,我经常遇到同样的问题:不是全部Assets具有相同的标识符。 例如:70% 有 ISIN ,有些有彭博代码,有些两者都有,有些只有 AccountingID来自
我遇到了错误 A potentially dangerous Request.Form value was detected from the client 当我部署我的应用程序时(当我通过本地主机运
使用 this 中的一些指导在关于理解决策树结构的 scikit-learn 教程中,我的想法是,也许查看两个连接节点之间发生的特征组合可能会提供一些关于潜在“交互”术语的见解。也就是说,通过查看给定
我是一名优秀的程序员,十分优秀!