Pointer arithmetic demo accesses out-of-bounds memory without warning (Ch 30 / 00.pointers.ipynb)
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ả
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
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của kangwonlee/2018pycpp
-
enhancement freshman-audience
Độ khó 3/5 1-3 giờ Mức phù hợp với người mới 68/100
kangwonlee/2018pycpp#76 ·
-
Intel assemblyĐang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
kangwonlee/2018pycpp#65 ·
-
CI in tutorial gitĐang mởenhancement
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
kangwonlee/2018pycpp#61 ·
-
Rust studyĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
kangwonlee/2018pycpp#56 · 1 bình luận ·
-
question
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
kangwonlee/2018pycpp#52 ·
Tất cả issue của kangwonlee/2018pycpp
Issue tương tự
-
Table: Space fires onActivate in single-selection mode — the reference doc and the JSDoc disagreeĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
sidorares/react-x11-components#764 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 71/100
t4t5/omdrop-owl#14 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 91/100
githubnext/gh-aw-workshop#4458 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
netbox status: needs triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
netbox-community/netbox#23376 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
wso2/docs-api-platform#529 ·
Maintainer thường phản hồi trong vòng 1 ngày