[clang-tidy] argument to operator delete is the address of a local stack variable, which is not memory allocated by 'new'

オープン
#359 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
cpp
領域
backend

調査の方向性

boost/multiprecision/number.hpp の 2005 行付近と boost/multiprecision/cpp_int.hpp の 1822-1904 行付近から始め、続いて 365 行の allocator パスと scoped_shared_storage の実装を調べます。報告された string 変換を伴う clang-tidy の診断を再現し、その警告が有効かどうかを判断し、結果として生じる動作を文書化またはテストします。

索引モデルが issue の本文から書いたものです。

説明

clang-tidy on a project brought this to my attention:

/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/ext/new_allocator.h:125:2: error: Argument to operator delete is the address of a local stack variable, which is not memory allocated by 'new' [clang-analyzer-cplusplus.NewDelete,-warnings-as-errors]
        ::operator delete(__p);
        ^
...
my_private_include_path/include/boost/multiprecision/number.hpp:2005:25: note: Calling 'number::str'
   std::string     s  = r.str(d, os.flags());
                        ^
my_private_include_path/include/boost/multiprecision/number.hpp:808:14: note: Calling 'cpp_int_backend::str'
      return m_backend.str(digits, f);
             ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1920:14: note: Calling 'cpp_int_backend::do_get_string'
      return do_get_string(f, trivial_tag());
             ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1822:11: note: Assuming the condition is false
      if ((f & std::ios_base::oct) == std::ios_base::oct)
          ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1822:7: note: Taking false branch
      if ((f & std::ios_base::oct) == std::ios_base::oct)
      ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1824:16: note: Assuming the condition is false
      else if ((f & std::ios_base::hex) == std::ios_base::hex)
               ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1824:12: note: Taking false branch
      else if ((f & std::ios_base::hex) == std::ios_base::hex)
           ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1830:11: note: 'base' is not equal to 8
      if (base == 8 || base == 16)
          ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1830:11: note: Left side of '||' is false
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1830:24: note: 'base' is not equal to 16
      if (base == 8 || base == 16)
                       ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1830:7: note: Taking false branch
      if (base == 8 || base == 16)
      ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1876:10: note: Taking false branch
         if (t.sign())
         ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1881:14: note: Assuming the condition is false
         if (this->size() == 1)
             ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1881:10: note: Taking false branch
         if (this->size() == 1)
         ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1889:13: note: Loop condition is false. Execution continues on line 364
            while (eval_get_sign(t) != 0)
            ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1904:10: note: Calling implicit destructor for 'cpp_int_backend<0, 0, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, std::allocator<unsigned long long>>'
         }
         ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:1904:10: note: Calling '~cpp_int_base'
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:364:11: note: Assuming field 'm_internal' is false
      if (!m_internal)
          ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:364:7: note: Taking true branch
      if (!m_internal)
      ^
my_private_include_path/include/boost/multiprecision/cpp_int.hpp:365:10: note: Calling 'new_allocator::deallocate'
         allocator().deallocate(limbs(), capacity());
         ^
/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/ext/new_allocator.h:125:2: note: Argument to operator delete is the address of a local stack variable, which is not memory allocated by 'new'
        ::operator delete(__p);
        ^

I am not sure but it seems that clang-tidy misinterprets the call to the custom allocator scoped_shared_storage.

主要言語
C++
スター
268
フォーク
130
平均マージ
1日 15時間
マージ済み PR(30日)
2

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

boostorg/multiprecision のほかの issue

boostorg/multiprecision の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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