Skip to content

Instantly share code, notes, and snippets.

@skiadas
Created February 15, 2020 16:12
Show Gist options
  • Save skiadas/9626a85c241afd89b673bdad0163499e to your computer and use it in GitHub Desktop.
Save skiadas/9626a85c241afd89b673bdad0163499e to your computer and use it in GitHub Desktop.
segfault example
// segfault_example
// author: Haris Skiadas
// date: 2-14-20
// Compile with something like:
// g++ segfault_example.cpp -ldw -g -pthread -lgtest -o segfault_example
// ./segfault_example
#include "gtest/gtest.h"
#define BACKWARD_HAS_DW 1
#include "backward.hpp"
backward::SignalHandling sh;
using namespace std;
class MyClass {
public:
MyClass() { }
int get_a() const { return *a; }
void set_a(int x) { *a = x; }
private:
int* a;
};
TEST(TestSimple, DefaultConstructor)
{
MyClass c1;
c1.set_a(10);
EXPECT_EQ(5, c1.get_a());
}
int main(int argc, char* argv[]){
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment