undefined behavior in do_fill_uninitialized_memory()
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 52/100
Direzione di ricerca
Inizia in boost/circular_buffer/debug.h, in do_fill_uninitialized_memory(), e rivedi il percorso di costruzione per copia per un circular_buffer vuoto. Riproduci l’esempio con GCC 9.1, -fsanitize=undefined e -DBOOST_CB_ENABLE_DEBUG=1; il lavoro è completato quando il caso di copia vuota non segnala più l’errore di puntatore nullo, mentre i riempimenti con valori diversi da zero continuano a essere verificati.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Using gcc 9.1 with -fsanitize=undefined and -DBOOST_CB_ENABLE_DEBUG=1, the following code results in a ubsan error: "boost/circular_buffer/debug.hpp:37:16: runtime error: null pointer passed as argument 1, which is declared to never be null".
using Q = boost::circular_buffer<int>;
Q q;
const Q q2(q);
The ubsan error is a result of the following code in circular_buffer/debug.h:
template <class T>
inline void do_fill_uninitialized_memory(T* data, std::size_t size_in_bytes) BOOST_NOEXCEPT {
std::memset(static_cast<void*>(data), UNINITIALIZED, size_in_bytes);
}
During copy construction, the function gets called with data == nullptr and size_in_bytes == 0. I believe that passing a null pointer to memset is technically undefined behavior even if the size is 0.
Changing the above function as follows avoids the ubsan error:
template <class T>
inline void do_fill_uninitialized_memory(T* data, std::size_t size_in_bytes) BOOST_NOEXCEPT {
if (size_in_bytes != 0u) {
std::memset(static_cast<void*>(data), UNINITIALIZED, size_in_bytes);
}
}
I had originally written it to check for data != nullptr, but since this is debug code I thought it seemed desirable to know if the function is ever called with data == null and size_in_bytes != 0. In any case, either way will prevent the ubsan error.
- Lingua principale
- C++
- Stelle
- 65
- Fork
- 64
- 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 boostorg/circular_buffer
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 25/100
boostorg/circular_buffer#53 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 48/100
boostorg/circular_buffer#51 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
boostorg/circular_buffer#48 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
boostorg/circular_buffer#47 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
boostorg/circular_buffer#46 · 4 commenti ·
Tutte le issue di boostorg/circular_buffer
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
flutter-webrtc/flutter-webrtc#2206 ·
-
litertlm-android AAR ships no consumer ProGuard rules → "mid == null" SIGABRT in minified apps Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
Component: GLib
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Mute ydb/tests/functional/dstool/test_canonical_requests.py.Test.test_group_take_snapshot in main Apertaai_reviewed
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
ydb-platform/ydb#53974 · 3 commenti ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
google/libultrahdr#485 ·