Pointer arithmetic demo accesses out-of-bounds memory without warning (Ch 30 / 00.pointers.ipynb)
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 1/5
- Tempo stimato
- Meno di un'ora
- Idoneità per principianti
- 78/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- cpp, jupyter-notebook
- Ambito
- documentation
Direzione di ricerca
Apri 30.pointers-and-memory-management/00.pointers.ipynb e ispeziona l'esempio int_ptr.cpp della cella 16. Sostituisci la configurazione con un singolo int con l'esempio valido basato su un array descritto nell'issue, quindi verifica che l'output mostrato dell'aritmetica dei puntatori non dereferenzi più memoria fuori dai limiti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Jupyter Notebook
- Stelle
- 3
- Fork
- 1
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di kangwonlee/2018pycpp
-
enhancement freshman-audience
Difficoltà 3/5 1-3 ore Idoneità per principianti 68/100
kangwonlee/2018pycpp#76 ·
-
Intel assembly Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
kangwonlee/2018pycpp#65 ·
-
CI in tutorial git Apertaenhancement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
kangwonlee/2018pycpp#61 ·
-
Rust study Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
kangwonlee/2018pycpp#56 · 1 commento ·
-
question
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
kangwonlee/2018pycpp#52 ·
Tutte le issue di kangwonlee/2018pycpp
Issue simili
-
Link Checker Report Apertaautomated issue report
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Humanity AI Aperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
numfocus/project-fundraising#166 ·
-
area:proxy bug security severity:low track:open-source
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100