×

# why SIGABRT error?

 0 Please help. My program is running into a SIGABRT error when I submit it. Question: Andrew and the Meatballs My Code: #include #include #include using namespace std; int main() { int t, n, m, c, temp; cin >> t; while (t--){ vector plates; cin >> n >> m; pair * sort_plates = new pair[n]; for (int a = 0; a < n; a++){ cin >> temp; plates.push_back(temp); } sort(plates.begin(), plates.end()); n--; c = n; bool flag = false; while (c >= 0 && flag == false){ for (int a = 0; a <= n - c; a++){ if (sort_plates[a].first > 0){ if (plates[c] <= sort_plates[a].first){ sort_plates[a].first -= plates[c]; sort_plates[a].second++; } } else { if (plates[c] <= m){ sort_plates[a].first = m - plates[c]; } else { sort_plates[a].first = m; } sort_plates[a].second = 1; } if (sort_plates[a].first == 0){ flag = true; cout << sort_plates[a].second << endl; a = n; } } c--; } if (flag == false){ cout << "-1" << endl; } } return 0; }  asked 30 Dec '13, 06:40 1●2●5●8 accept rate: 0% 4★kunal361 6.0k●13●32●72

 3 SIGABRT is commonly used by libc and other libraries to abort the progamm in case of critical errors. For example, glibc sends an SIGABRT in case of a detected double-free or other heap corruptions. Also, most "assert" implementaions make use of SIGABRT in case of a failed assert. Furthermore, SIGABRT can be send from any other process like any other signal. Of course, the sending process needs to run as same user or root. It usually happens when there is a problem with memory allocation. It happened to me when I my program was trying to allocate an array with negative size. abort() sends the calling process the SIGABRT signal, this is how abort() basically works. abort() is usually called by library functions which detect an internal error or some seriously broken constraint. For example malloc() will call abort() if its interal structures are damaged by a heap overflow. answered 30 Dec '13, 09:39 1.2k●2●11●16 accept rate: 10%
 0 i had encountered SIGABRT while using "sort" as well i ended up writing my own "compare" function for "sort", which did the same thing as what i expected the default compare of "sort" to do, and that helped me get AC. i still don't know why it worked. "sort" seems to act a bit weird while working with vectors.. answered 12 Nov '17, 22:57 3★abhi011 0●1●1●3 accept rate: 0%
 0 I also encountered the same error and the main reason was: vector score(n); for(int i = 1 ; i>score[i]; } Here you can see the score vector has score[0] to score[n-1]. But i tried to access the score[n] in line 3, which is not allowed. answered 06 Dec, 03:36 1 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×2,647
×519
×59

question asked: 30 Dec '13, 06:40

question was seen: 27,418 times

last updated: 06 Dec, 03:38