[英]Segmentation fault on malloc on one test case
Can any guru please assist me in identifying a segmentation fault? 任何上师都可以帮助我确定细分错误吗? The segmentation fault seem to only be problematic on one of my test cases and appears to happen when allocating memory for a particular pointer within a struct.
分段错误似乎仅在我的一个测试用例中有问题,并且似乎在为结构中的特定指针分配内存时发生。 This works in all other test cases, which makes it kind of strange.
这在所有其他测试用例中都有效,这使它有点奇怪。
Here's my code: 这是我的代码:
http://pastebin.com/dfUqQnYy - the segmentation fault occurs at line 453. http://pastebin.com/dfUqQnYy-分段错误发生在第453行。
speeches[i].who = malloc(nb_of_sirs_involved * sizeof(int));
Here are example inputs passed as arguments (using cat): 以下是作为参数传递的示例输入(使用cat):
http://pastebin.com/YWv1F88G - the one causing the segmentation fault. http://pastebin.com/YWv1F88G-引起分段错误的一个。
http://pastebin.com/i0V7KNH3 - one of the other test cases that do not cause segmentation fault. http://pastebin.com/i0V7KNH3-其他不会导致分段错误的测试用例之一。
I'm not sure what is wrong. 我不知道怎么了。 What causes a malloc to fail?
是什么导致malloc失败? I'm sure I have enough memory to allocate!
我确定我有足够的内存来分配!
I found problem. 我发现了问题。 It was a boolean variable which wasn't initialised... I don't know how it can be related to speeches[i].who but it fixed my problem.
这是一个尚未初始化的布尔变量...我不知道它与语音[i] .who有什么关系,但它解决了我的问题。 Thanks all.
谢谢大家
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.