Segmentation fault depending on string length?

后端 未结 2 963
后悔当初
后悔当初 2021-01-27 01:08

I am writing a program that will read lines from an infile using getline into strings, convert the strings to c-strings containing the first m nonwhitespace characters of the st

相关标签:
2条回答
  • 2021-01-27 01:25

    I am not sure why the backtrace is pointing to string input; but when you are copying row into map. if mapsize is bigger than the size of row, you could well end up seg-faulting. This will be more common for a bigger mapsize.

    you also may well be stomping over return addresses on the stack that could be causing the "wrong" core-dump.

    0 讨论(0)
  • map is a VLA, allocated on the stack, so I'd guess that your problem is that you get a stack overflow. gdb points a the construction of input because that's the first thing that gets constructed on this overflowed stack.

    0 讨论(0)
提交回复
热议问题