Category : segmentation-fault

I implemented a custom operator new to track allocation behaviour. It allocates 8 bytes more than requested to prepend the allocated size as std::size_t. void *operator new(std::size_t count) { auto *pBase = reinterpret_cast<std::size_t*>(std::malloc(count + sizeof(std::size_t))); pBase[0] = count; auto *pUserMem = reinterpret_cast<std::byte*>(pBase) + sizeof(std::size_t); return reinterpret_cast<void*>(pUserMem); } Additionally I reimplemented operator delete to (in a ..

Read more

#include<bits/stdc++.h> using namespace std; vector<string> splitter(string s) { vector<string>v; int start=0; int end=0; while(end<s.length()) { while(s[end]!=’ ‘) { end++; } v.push_back(s.substr(start, end-start)); end++; start=end; } return v; } int main() { // Write your code here string s; getline(cin, s); cout<<"here";//Getting SIGSEGV error if this line is removed vector<string> v=splitter(s); map<string, int> m; int flag=1; ..

Read more

I’m having trouble manipulating a doubly linked list. I’m pretty sure I have my addNode(), getCount(), printList(), and getNode() working fine, but when executing, I get to right around my exists() and deleteNode() methods and I get a segmentation fault. exists() checks to see if a specific node exists, and deleteNode() passes in an id, ..

Read more