Abort instead of segfault with clear memory violation

后端 未结 6 548
渐次进展
渐次进展 2021-01-13 18:48

I came upon this weird behaviour when dealing with C strings. This is an exercise from the K&R book where I was supposed to write a function that appends one string onto

6条回答
  •  走了就别回头了
    2021-01-13 19:18

    There's no seg fault or even an overwrite because it can use the memory of the second string and still function. Even give the correct answer. The abort is a sign that the program realized something was wrong. Try reversing the order in which you declare the strings and try again. It probably won't be as pleasant.

提交回复
热议问题