ConcreteShadowNode::getConcreteSharedProps() returns a reference to a temporary
維護者通常 2 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
閱讀 packages/react-native/ReactCommon/react/renderer/core/ConcreteShadowNode.h,特別是第 144–148 行,並檢查 getConcreteSharedProps() 的回傳型別和實作。使用 -Wreturn-stack-address 編譯提供的重現程式,以確認該警告,然後更新此方法,使其回傳值保持有效,同時保留要求的名稱和 const 性質。重現程式在沒有該警告的情況下編譯成功,即為完成。
由索引模型根據 Issue 內容生成。
描述
Description
ConcreteShadowNode::getConcreteSharedProps() (ConcreteShadowNode.h) is declared to return const std::shared_ptr<const ConcreteProps> & and returns std::static_pointer_cast<const ConcreteProps>(props_), a temporary destroyed as the function returns, so every caller gets a reference to a destroyed shared_ptr. Nitro's generated view components called it until margelo/nitro#1502 moved them to getProps().
Steps to reproduce
- Clone the reproducer below and run
bash repro.shon Ubuntu 24.04 withclang git libboost-dev libgoogle-glog-dev libdouble-conversion-devfrom apt, or thedocker runline in its README. It clones react-native'smain, and folly, fast_float and fmt at the versionspackages/react-native/gradle/libs.versions.tomlpins. - It compiles
repro.cpp, which declares a component's shadow node,ConcreteShadowNode<ProbeComponentName, ShadowNode, Props>, and a function that returnsshadowNode.getConcreteSharedProps().
Expected: repro.cpp compiles without a warning: getConcreteSharedProps() returns the shared_ptr by value, or a reference to one that outlives the call, and keeps its name and its const.
Actual: clang reports returning reference to local temporary object at the function's return, ConcreteShadowNode.h:147.
React Native Version
0.88.1
Affected Platforms
Other (please specify)
Output of npx @react-native-community/cli info
Not an app. The reproducer compiles ReactCommon from react-native's main at b9a83f3 (0.88.0 and 0.88.1 have the
same getConcreteSharedProps), on Ubuntu 24.04 with clang 18.1.3, folly 2024.11.18.00, fast_float 8.0.0 and
fmt 12.1.0. ReactCommon is shared by Android and iOS.
Stacktrace or Logs
react/react-native b9a83f3, Ubuntu clang version 18.1.3 (1ubuntu1), Linux x86_64
folly 2024.11.18.00, fast_float 8.0.0 and fmt 12.1.0, as libs.versions.toml pins them
compiling repro.cpp, whose sharedPropsOf() returns shadowNode.getConcreteSharedProps(), with -Wreturn-stack-address
ReactCommon/react/renderer/core/ConcreteShadowNode.h:147:12: warning: returning reference to local temporary object [-Wreturn-stack-address]
147 | return std::static_pointer_cast<const ConcreteProps>(props_);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
summary: react/react-native b9a83f3: clang reports that ConcreteShadowNode::getConcreteSharedProps() returns a reference to a temporary
MANDATORY Reproducer
https://github.com/YevheniiKotyrlo/concrete-shadow-node-dangling-shared-props
- 主要語言
- C++
- 星號
- 127k
- 分支
- 25.5k
- 平均合併
- 3 天 18 小時
- 30 天內合併 PR
- 188
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
react/react-native 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 76/100
react/react-native#59945 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
react/react-native#59942 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 76/100
react/react-native#59939 ·
維護者通常 2 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
react/react-native#59929 · 1 則留言 ·
維護者通常 2 天內回覆
-
iOS Fabric pointer-handler reset leaves the next lone touch non-primary可能已有人在做 @alleneubank 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 68/100
react/react-native#59919 ·
維護者通常 2 天內回覆
查看 react/react-native 的全部 Issue
相似的 Issue
-
type:bug
難度 2/5 1-3 小時 新手友好度 65/100
tensorflow/tflite-micro#3995 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
-
not for AI lovers
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
VT: Backend
難度 2/5 1-3 小時 新手友好度 82/100
contour-terminal/contour#2314 ·
維護者通常 1 天內回覆