4 ms·
If you use memcpy and your destination buffer is too small you don’t crash hard with any certainty, your program might even appear to work. Moreover, most of t
by repiret 8y ago
If you use memcpy and your destination buffer is too small you don’t crash hard with any certainty, your program might even appear to work.
Moreover, most of the time I’m either certain the output buffer is large enough (maybe because I just allocated it) or I really do want the output buffer to have a truncated string. Strncpy’s two dumb behaviors that I almost never want is to pad the destination buffer with zeros if the source string is smaller and to leave the destination I terminated if the source is longer.