mirror of
https://github.com/XRPLF/rippled.git
synced 2026-06-02 16:26:48 +00:00
Co-authored-by: semgrep-companion-app[bot] <218312740+semgrep-companion-app[bot]@users.noreply.github.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
29 lines
588 B
C++
29 lines
588 B
C++
#include <atomic>
|
|
#include <cstddef>
|
|
#include <iostream>
|
|
|
|
#if defined(__clang__) || defined(__GNUC__)
|
|
__attribute__((noinline))
|
|
#elif defined(_MSC_VER)
|
|
__declspec(noinline)
|
|
#endif
|
|
int
|
|
read_after_free(volatile int* array, std::size_t index)
|
|
{
|
|
std::atomic_signal_fence(std::memory_order_seq_cst);
|
|
int value = array[index];
|
|
std::atomic_signal_fence(std::memory_order_seq_cst);
|
|
return value;
|
|
}
|
|
|
|
int
|
|
main()
|
|
{
|
|
int* array = new int[5]{10, 20, 30, 40, 50};
|
|
delete[] array;
|
|
|
|
std::cout << "Value at index 2: " << read_after_free(array, 2) << std::endl;
|
|
|
|
return 0;
|
|
}
|