Skip to content

Instantly share code, notes, and snippets.

@orbitcowboy
Created February 2, 2016 07:29
Show Gist options
  • Save orbitcowboy/ac8b91b98cc8fbc1c478 to your computer and use it in GitHub Desktop.
Save orbitcowboy/ac8b91b98cc8fbc1c478 to your computer and use it in GitHub Desktop.
#include <inttypes.h>
#include <iostream>
#include <cstdio>
// def.h
struct INFO {
uint32_t val1;
uint32_t val2;
};
struct INFO_LIST {
uint32_t id;
struct INFO * data;
};
// util.cpp
void print_request(const struct INFO_LIST req)
{
fprintf(stdout, "%u\t%u\t%u\n", req.id, req.data->val1, req.data->val2);
}
// A.cpp
int parse_ie()
{
struct INFO_LIST req;
req.id = 10;
req.data = new INFO();
req.data->val1 = 101;
req.data->val2 = 102;
print_request(req);
}
// B.cpp
int parse_chrome()
{
struct INFO_LIST req;
req.id = 20;
print_request(req); // core dump here!
}
/*
$ cppcheck test.cpp
Checking test.cpp...
[test.cpp:37]: (error) Uninitialized struct member: req.data
$ cppcheck --version
Cppcheck 1.73 dev
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment