1
char *word = malloc(sizeof(char) * (pos + 1));

is producing an SIGTRAP error. pos is an int.

How do I know this is the line? Process of elimination with break points.

I searched and did not find any information on this function producing this error. What should I do?

alk
  • 69,737
  • 10
  • 105
  • 255
Thomas
  • 6,032
  • 6
  • 41
  • 79
  • 2
    [see here](http://stackoverflow.com/questions/3475262/what-causes-a-sigtrap-in-a-debug-session) – M.M Oct 12 '14 at 04:41
  • How do I find what might have corrupted the heap? I'm using windows and codelite IDE. – Thomas Oct 12 '14 at 04:43
  • "*How do I find what might have corrupted the heap?*" Run your program using a memory checker. I'd recommend Valgrind (http://valgrind.org), but am not sure whether it's available on you platfrom. – alk Oct 12 '14 at 11:06
  • 1
    Also `sizeof (char)` is `1` by definition. – alk Oct 12 '14 at 11:07
  • 1
    Also^2 `malloc()` takes a `size_t` (which is unsigned) as argument, not an `int`. Saying this, could by any chance the `pos - 1` in your source had evaluated to a negative value, that is `pos` had been `<=0`? – alk Oct 12 '14 at 11:10

1 Answers1

2

There are many memory debuggers available on Windows (though I haven't tried them by myself):

I'd recommend you to try Application Verifier from MS:

It should be able to catch heap corruption.

But before you start relying on such a large and complicated software, you can simply printf the value of arguments to malloc() and free() at all places. You will find something odd in the output.

Community
  • 1
  • 1
nodakai
  • 7,773
  • 3
  • 30
  • 60