Implementing a string copy function in C

前端 未结 9 1877
谎友^
谎友^ 2020-12-20 00:57

At a recent job interview, I was asked to implement my own string copy function. I managed to write code that I believe works to an extent. However, when I returned home to

9条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-20 01:45

    No, you're writing past the buffer and overwriting (in this case) the rest of your stack past buffer. This is very dangerous behavior.

    In general, you should always create methods that supply limits. In most C libraries, these methods are denoted by an n in the method name.

提交回复
热议问题