Questions tagged [dangling-pointer]
Dangling pointers and wild pointers in computer programming are pointers that do not point to a valid object of the appropriate type.
dangling-pointer
171
questions
0
votes
1
answer
43
views
Segfault in Rust when calling a function returned by a cdylib crate function
If I have a fn(&mut Box<fn()>) in a cdylib crate, and it sets the value of the Box to another function defined in the crate, I get a segmentation fault when calling the resulted function.
I ...
0
votes
0
answers
57
views
Why doesn't std::array<T,N>::operator[] return an rvalue reference for rvalue object? [duplicate]
std::array<T,N>::operator[] always returns an lvalue reference (const if needed), but what can possibly be the use of a line of code like this, which is valid C++?
std::array<int,1>{1}[0] =...
1
vote
0
answers
30
views
Detecting dangling pointer caused by realloc using static analyze tools
I use some external lib written in C that implement hash table.
When hash table size need to grow it uses realloc to double the memory space for keys/values.
I familiar with this behavior but others ...
2
votes
1
answer
104
views
Why does the initialization of a reference to the base class object with the child class object lead to a dangling reference?
In the code below, I defined 4 classes:
class A.
base class B_parent.
derived from B_parent class B_child which contains a reference to an object of class A, the reference is initialized by the ...
1
vote
1
answer
4k
views
How to run Valgrind and other tools to check memory leaks in Visual studio code?
I have installed "Valgrind Task Integration" extension in Visual studio code and after restarting VS code and typed the following Valgrind command in terminal,
"valgrind --leak-check=...
-2
votes
2
answers
128
views
Dangling pointer issue C++
I'm making a game engine and I have run into a problem with destroying elements.
For example I have some cameras that follow and look at an target (a gameobject or an actor).
Later in the game the ...
0
votes
1
answer
35
views
OLECHAR used as pointer - will it dangling pointer if not nullptr? Function CoTaskMemFree()
I generate a GUID and then save it in OLECHAR* with StringFromCLSID(). If I create a function which returns an OLECHAR and not nullptr the OLECHAR after using CoTaskMemFree() - will it cause dangling ...
0
votes
0
answers
48
views
question on properly managing reference members in a local class in C++
Is the reason why I got a garbage value because of the following or am I wrong?
the Other object o passed as an argument to the Inner constructor, goes out of scope after the Inner object has been ...
0
votes
1
answer
51
views
Does the following program contain a dangling reference?
I have the following program:
#include <iostream>
#include <string>
using namespace std;
using int_arr = int[3];
int& f(int_arr& arr, int index)
{
return arr[index];
}
int ...
0
votes
1
answer
233
views
How to look for dangling pointers?
I'm trying to build a class for a linked list in C++. My professor says that I have a dangling pointer in my code. I've spent hours looking for it but I just can't find it no matter what. I tried ...
3
votes
1
answer
114
views
Coroutines: Do co_yielded string_views dangle?
I want to mix up the co_yielding string literals and std::strings
Generator<std::string_view> range(int first, const int last) {
while (first < last) {
char ch = first++;
...
1
vote
0
answers
39
views
Will there be dangling references to map values if it gets resized? [duplicate]
Would reference to values in std::map or std::unordered_map be valid/maintained if the map's being inserted new elements or removed from?
For example, is the below code safe? Or would there be ...
4
votes
2
answers
377
views
prevent initializing std::optional<std::reference_wrapper<const T>> with rvalue std::optional<T>
std::reference_wrapper cannot be bound to rvalue reference to prevent dangling pointer.
However, with combination of std::optional, it seems that rvalue could be bound.
That is, std::...
1
vote
1
answer
351
views
Return a shared pointer from a function vs Capturing a shared pointer in a Lambda
I am constructing a shared pointer in a function_1 and giving it as a capture to a lambda.
I think this is an issue, could you please confirm if this safe or I am right and I shoudn't be doing this?
#...
-1
votes
1
answer
127
views
Why doesn't GCC warn me about storing a reference to a local variable?
Suppose I'm compiling the following code:
struct foo {
const int& x_;
foo(const int x) : x_(x) { }
};
int main()
{
int x = 1;
auto b2 = foo{x};
return b2.x_;
}
This program ...