Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở Phù hợp với người mới
#75 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
1/5
Thời gian dự kiến
Dưới một giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Ít trao đổi
Công nghệ
cpp, jupyter-notebook
Lĩnh vực
documentation

Hướng nghiên cứu

Mở 30.pointers-and-memory-management/00.pointers.ipynb và kiểm tra ví dụ int_ptr.cpp trong ô 16. Thay thế thiết lập sử dụng một int duy nhất bằng ví dụ hợp lệ dựa trên array được mô tả trong issue, sau đó xác minh rằng đầu ra phép toán số học con trỏ được hiển thị không còn dereference vùng nhớ nằm ngoài giới hạn.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Jupyter Notebook
Star
3
Fork
1
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của kangwonlee/2018pycpp

Tất cả issue của kangwonlee/2018pycpp

Issue tương tự

Thêm issue về Documentation

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.