Add memcheck errors for aligned and sized allocations and deallocations
[valgrind.git] / memcheck / tests / freebsd / bug470713.cpp
blob1d34ac6604b9a485bc58de00b5b5a090fbb3bfd2
1 // roughly based on the code for Firefox class BinaryPath
2 // https://searchfox.org/mozilla-central/source/xpcom/build/BinaryPath.h#185
4 #include <iostream>
5 #include <sys/types.h>
6 #include <sys/sysctl.h>
7 #include <limits.h>
8 #include <string>
9 #include <memory>
11 using std::cerr;
12 using std::cout;
13 using std::string;
15 int main(int argc, char **argv)
17 int mib[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
18 size_t len;
20 if (sysctl(mib, 4, NULL, &len, NULL, 0) != 0) {
21 cout << "sysctl failed to get path length: " << strerror(errno) << '\n';
22 return -1;
25 std::unique_ptr<char[]> aResult(new char[len]);
27 if (sysctl(mib, 4, aResult.get(), &len, NULL, 0) != 0) {
28 cout << "sysctl failed to get path: " << strerror(errno) << '\n';
29 return -1;
32 if (string(aResult.get()) == argv[1]) {
33 cout << "OK\n";
34 } else {
35 cout << "Not OK aResult " << aResult << " argv[1] " << argv[1] << '\n';
38 if (sysctl(mib, 4, NULL, NULL, NULL, 0) != -1) {
39 cout << "OK syscall failed\n";
40 return -1;
41 } else {
42 cout << "sysctl succeeded when it should have failed\n";