【问题标题】:Binding dereferenced null pointer to reference has undefined behavior Xcode 9将取消引用的空指针绑定到引用具有未定义的行为 Xcode 9
【发布时间】:2018-07-11 07:21:24
【问题描述】:

我在 Xcode 9 上运行 Objective-C 项目并遇到此错误,其中指出

编辑:使用 AutoDesk 的 FBXSDK。我认为它与 Xcode 9 中新的 clang 版本有关(该项目是用 Xcode 7 编写的)。如果我理解正确,我需要从这个link 将clang 恢复到旧版本。使用虚幻引擎时同样的问题。

将取消引用的空指针绑定到引用具有未定义的行为

我尝试运行的脚本如下

const FbxProperty& StaticInit(FbxObject* pObject, const char* pName, const FbxReference& pValue, bool pForceSet, FbxPropertyFlags::EFlags pFlags=FbxPropertyFlags::eNone)
{
    return StaticInit(pObject, pName, FbxGetDataTypeFromEnum(FbxTypeOf(*((FbxReference*)0))), pValue, pForceSet, pFlags);
}

StaticInit 方法

const FbxProperty& StaticInit(FbxObject* pObject, const char* pName, const FbxDataType& pDataType, const FbxReference& pValue, bool pForceSet, FbxPropertyFlags::EFlags pFlags=FbxPropertyFlags::eNone)
{
    bool lWasFound = false;
    *this = Create(pObject, pDataType, pName, "", true, &lWasFound);
    if( pForceSet || !lWasFound )
    {
        ModifyFlag(pFlags, true);   // modify the flags before we set the value
        Set(pValue);            // since we will trigger callbacks in there!
    }
    ModifyFlag(FbxPropertyFlags::eStatic, true);
    return *this;
}

Xcode 底层 *((FbxReference*)0 作为一个错误。

Error Image

【问题讨论】:

  • 取消引用 null 确实是未定义的行为——您的代码正在执行与 *nullptr 等效的操作,这没有任何意义。 ObjectTypeOf 是做什么的?如果它取决于传入的值,那么您的程序格式不正确。
  • @ItaiFerber 是的,你是对的,我会编辑代码
  • 不幸的是,这并不太清楚。我们需要知道 FbxTypeOf 做了什么,以便弄清楚如何帮助您改进代码。
  • AutoDesk 的 FBxSDK
  • 在寻求帮助时,最好将您问题中的所有信息包含在问题中,而不是让其他人谷歌搜索。在这种情况下,看起来FbXTypeOfdefined here。基于此,看起来这种用法非常荒谬(在所有方面)。您应该能够用eFbxEnum 替换所有FbxTypeOf(...),因为thats all this function ever returns

标签: c++ ios objective-c xcode xcode9


【解决方案1】:

将0改为1即可解决。

return StaticInit(pObject, pName, FbxGetDataTypeFromEnum(FbxTypeOf(*((FbxReference*)1))), pValue, pForceSet, pFlags);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-11
    • 1970-01-01
    • 2011-10-31
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    • 2016-09-17
    • 1970-01-01
    相关资源
    最近更新 更多