dangling-pointer Questions
8
Solved
Swift has:
Strong References
Weak References
Unowned References
How is an unowned reference different from a weak reference?
When is it safe to use an unowned reference?
Are unowned reference...
Phosphoresce asked 3/6, 2014 at 9:27
8
Solved
I don't understand concept of dangling pointer, was googling around, and writing test methods to find one.
I just wonder is this a dangling pointer? As whatever example I found was returning someth...
Idolater asked 1/8, 2013 at 14:45
1
It's common knowledge that returning a pointer to a stack variable is generally a bad idea:
int* foo() {
int i = 0;
return &i;
}
int main() {
int* p = foo();
}
In the example above, my und...
Courante asked 11/6, 2022 at 9:34
4
Solved
I've read How to demonstrate memory leak and zombie objects in Xcode Instruments? but that's for objective-c. The steps don't apply.
From reading here I've understood zombies are objects which ar...
Pearcy asked 29/10, 2018 at 16:15
1
Solved
During constant expression evaluation in C++17, shall the compiler consider any pointer addressing a valid object unequal to any pointer addressing an object after the end of its lifetime?
For exam...
Twum asked 7/10, 2021 at 7:55
3
We can only de-reference a valid pointer and we can only check the address that a dangling built-in pointer points to. We cannot access its value (the value in the address of object it is poi...
Larimer asked 30/9, 2021 at 19:28
2
I'd think that the VS2019 suggestion would create a dangling reference situation, but I tested it out, and it seems to work. What is happening here?
template<typename MessageType>
class Q...
Ecclesiolatry asked 20/5, 2021 at 0:39
3
What set of GCC options provide the best protection against memory corruption vulnerabilities such as Buffer Overflows, and Dangling Pointers? Does GCC provide any type of ROP chain mitigation? Are...
Dumond asked 24/11, 2012 at 19:0
1
Solved
Consider a method that returns a std::string_view either from a method that returns a const std::string& or from an empty string. To my surprise, writing the method this way results in a dangli...
Multi asked 17/6, 2019 at 15:15
2
Solved
According to an article (here and there) this code is an erroneous use-after free example:
#include <iostream>
#include <string>
#include <string_view>
int main() {
std::string...
Stank asked 22/4, 2019 at 7:0
1
Solved
std::string &func(int vlu)
{
std::string str;
str = std::to_string(vlu) + "something";
return str;
}
the function above is unsafe clearly.
Following is another version.
std::string &...
Godred asked 29/10, 2018 at 10:52
2
I have a pointer and by default it carries NULL then it waits for some event and gets a value if the event happens, later I am freeing the pointer somewhere else but even after freeing the pointer ...
Verbality asked 11/9, 2018 at 4:52
1
I'm trying to explain to someone why they have a dangling pointer and how free actually works (and that pointers are values and thus are passed-by-value), but for that I think I need a way to print...
Bernadinebernadotte asked 14/7, 2018 at 23:20
6
I'm writing Python bindings for a C library that uses shared memory buffers to store its internal state. The allocation and freeing of these buffers is done outside of Python by the library itself,...
Coppery asked 23/6, 2016 at 10:20
2
We have already known that use-after-free vulnerabilities could cause the security problems. Since the use-after-free error is born from dangling pointer, my question is that if the dangling pointe...
Martellato asked 9/1, 2018 at 4:56
1
Solved
I have been reading Rust and Go in parallel and I see subtle differences in how both these languages deal with dangling pointers and the problems it causes. For example, here is a version in Rust:
...
Reeducate asked 28/10, 2017 at 7:55
2
Solved
I had to implement a function that looked like this:
MyList * sum (MyList * l1, MyList * l2) {
MyList * newlist = new MyList();
//Adds two objects and place the result in a third new list
retur...
Vortumnus asked 30/8, 2017 at 16:13
3
Solved
I have an inner lambda that uses one of the referenced variables of the outer lambda like this:
int x=0;
auto outer=[&](){
return [&](){
x=5;
};
};
auto inner= outer();
inner();
...
Lawler asked 24/4, 2017 at 9:10
3
Solved
Clang 3.9 extremely reuses memory used by temporaries.
This code is UB (simplified code):
template <class T>
class my_optional
{
public:
bool has{ false };
T value;
const T& get_or_...
Pb asked 20/2, 2017 at 8:54
6
Solved
std::vector has the member function at() as a safe alternative to operator[], so that bound checking is applied and no dangling references are created:
void foo(std::vector<int> const&x)...
Anthea asked 18/8, 2015 at 8:22
5
Solved
Is saying delete pointer and pointer = nullptr the same? Probably not, but does the latter free up memory? What about delete pointer; pointer = nullptr / pointer = nullptr; delete pointer? Wh...
Overcurious asked 24/7, 2015 at 20:10
1
Solved
I know that Undefined Behaviour, once it has happened, makes it impossible to think about the code any longer. I am convinced, completely. I even think I should not dig too much into understanding ...
Indorse asked 21/6, 2015 at 17:18
3
Is it legal to compare dangling pointers?
int *p, *q;
{
int a;
p = &a;
}
{
int b;
q = &b;
}
std::cout << (p == q) << '\n';
Note how both p and q point to objects that hav...
Slily asked 7/6, 2015 at 13:27
3
Solved
I'm new to C++ and would like to ask if the code below is an example of a dangling pointer or a memory leak because it is pointing outside the dynamically allocated array:
int * n = new int[10];
f...
Lard asked 14/3, 2015 at 14:25
5
Solved
In the stack, memory is reserved for main which we call stack frame for the main function.
When we call the Add function, memory is reserved on top of the stack. In the Add function stack frame, a...
Aeroscope asked 15/1, 2015 at 12:32
1 Next >
© 2022 - 2024 — McMap. All rights reserved.