Author | Message | Time |
---|---|---|
Yoni | Here is some code I wrote today for practice. This code has a terrible, evil bug that causes it to seg-fault. Can you spot the bug? (Note: Compiling it = cheating. Compilation with -Wall reveals the answer.) [code] ... irrelevant code snipped ... bool HeapEmpty() { return HeapSize == 0; } void HandleGroup(uint i) { // Is the heap empty? if (HeapEmpty()) { // Nothing to do with this group =\ return; } // Get the currently valid trip that has the least chance of attracting more groups. uint TIdx = HeapExtractMin(); // Match! NumMatched++; Match[Arr[i].Index + 1] = TIdx + 1; } ... irrelevant code snipped ... [/code] | July 29, 2005, 8:32 PM |
Mangix | either the uint thing or something else :(. | July 29, 2005, 8:59 PM |
Newby | It's never going to return, even if the heap is empty. [quote][color=black]Change "=\" to "=/" is my best guess. It seems you commented out return on accident. The only reason I know this is because I have done the same thing (though it would seem that my mistake (forgetting to add to a number) is less severe than yours). Yay for syntax highlighting! I've never coded in pico since. vim for life.[/color][/quote] | July 29, 2005, 9:49 PM |
Yoni | Newby rocks. [quote][color=black]Actually, it might return, just not from the "return;" line. :) But, as soon as we hit HeapExtractMin(), it tries to extract from an empty heap, which sometimes crashes and otherwise returns junk.[/color][/quote] | July 29, 2005, 10:12 PM |
Newby | [quote author=Yoni link=topic=12367.msg122461#msg122461 date=1122675133] Newby rocks. [quote][color=black]Actually, it might return, just not from the "return;" line. :) But, as soon as we hit HeapExtractMin(), it tries to extract from an empty heap, which sometimes crashes and otherwise returns junk.[/color][/quote] [/quote] :) [quote][color=black]Yeah, I guess I should have specified that it won't return from that return line if no heap exists. That's also a reason why I use /* code blocks */ :)[/color][/quote] | July 29, 2005, 11:04 PM |
Yoni | :) | July 30, 2005, 5:24 AM |
Quarantine | [color=Black]Why do you talk like this? [/color] | July 30, 2005, 5:43 PM |
R.a.B.B.i.T | [color=black]Cause they want to look cool[/color] | July 30, 2005, 6:47 PM |
Yoni | It's a spoiler blocker. If you don't want to see the answer you don't have to. | July 31, 2005, 8:22 PM |
Soul Taker | I think they're using a different theme, since not all themes have black quotes. | July 31, 2005, 11:23 PM |