ConcreteShadowNode::getConcreteSharedProps() returns a reference to a temporary

オープン 初心者向け
#59,944 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp, react-native
領域
mobile

調査の方向性

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
  1. Clone the reproducer below and run bash repro.sh on Ubuntu 24.04 with clang git libboost-dev libgoogle-glog-dev libdouble-conversion-dev from apt, or the docker run line in its README. It clones react-native's main, and folly, fast_float and fmt at the versions packages/react-native/gradle/libs.versions.toml pins.
  2. It compiles repro.cpp, which declares a component's shadow node, ConcreteShadowNode<ProbeComponentName, ShadowNode, Props>, and a function that returns shadowNode.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時間
マージ済み PR(30日)
188

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

react/react-native のほかの issue

react/react-native の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。