Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Pointer arithmetic demo accesses out-of-bounds memory without warning (Ch 30 / 00.pointers.ipynb)

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

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

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
cpp, jupyter-notebook
領域
documentation

調査の方向性

30.pointers-and-memory-management/00.pointers.ipynb を開き、セル 16 の int_ptr.cpp の例を確認してください。単一の int を使ったセットアップを、issue で説明されている有効な配列ベースの例に置き換え、その後、表示されるポインター算術の出力が範囲外のメモリをデリファレンスしなくなっていることを検証してください。

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

説明

bug

In 30.pointers-and-memory-management/00.pointers.ipynb, the int_ptr.cpp example (cell 16) declares a single int i = 0; and then performs pointer arithmetic that dereferences memory past i:

int i = 0;
int *p = &i;
// ...
cout << "*(p + 1)  = " << ... << *(p + 1) << '\n';  // dereferencing OOB
cout << "*(p + 2)  = " << ... << *(p + 2) << '\n';  // dereferencing OOB

This is undefined behavior. The C++ standard permits p+1 (one-past-the-end pointer arithmetic) but explicitly forbids dereferencing it when p doesn't point into an array. The demo "works" because the runtime happens to allow reading adjacent stack memory, but the output is shown to students as if it were a normal pattern to learn from — which risks teaching the wrong mental model.

Suggested fix (preferred: option 1)

Option 1 — make the example valid by using an actual array:

int arr[3] = {0, 1, 2};
int *p = arr;
// (p+1) and (p+2) are now valid dereferences into arr[1] and arr[2]

Option 2 — keep the example but add a markdown cell explicitly noting this is UB, and that the output happens to read adjacent stack memory (sometimes &p and parts of the stack frame).

Option 1 is cleaner for a teaching context: students see correct pointer arithmetic without needing the UB sidebar.

Context

Surfaced during Ch 30 evaluation. Small isolated change; pairs well with the delete[] bug fix as another "first commit" candidate.

主要言語
Jupyter Notebook
スター
3
フォーク
1
PR マージ指標
30日以内にマージされた PR はありません

環境構築

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

はじめの一歩

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

kangwonlee/2018pycpp のほかの issue

kangwonlee/2018pycpp の issue をすべて見る

似ている issue

Documentation の issue をもっと見る

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

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