# Strcpy and strcat

**URL:** <https://forum.arduino.cc/t/strcpy-and-strcat/880153>\
**Category:** Programming\
**Created:** [June 30, 2021, 1:03pm UTC](https://forum.arduino.cc/t/strcpy-and-strcat/880153 "2021-06-30T13:03:24Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![drmpf](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drmpf/32/1126438_2.png) [@drmpf](https://forum.arduino.cc/u/drmpf)\
**Post date:** [June 30, 2021, 4:17pm UTC](https://forum.arduino.cc/t/strcpy-and-strcat/880153/6 "2021-06-30T16:17:48Z")

</div>

Both strcpy and particularly strcat can 'overflow' the memory allocated for the result.  
The 'safe' versions are strlcpy and strlcat which test/prevent overflows  
See [strlcpy\_strlcat.ino](https://www.forward.com.au/pfod/ArduinoProgramming/SafeString/strlcpy_strlcat.ino) for examples of their use.

In the above #5 examples you would get a buffer/memory overflow if you tried to add more than 24 chars to text. In that case your sketch usually just crashes, which means no debug prints to say what was wrong.  
See this post for an example [Use of string char causes Arduino code to restart](https://forum.arduino.cc/t/use-of-string-char-causes-arduino-code-to-restart/699001)

I also have a [SafeString library](https://www.forward.com.au/pfod/ArduinoProgramming/SafeString/index.html) that works on char[]s but guards against buffer overflows and prints a detailed message if you get the size of buffer wrong (no crashes)  
SafeString provides safe high level methods for working with text, like trim, replace, substring etc

---

_[View the full topic](https://forum.arduino.cc/t/strcpy-and-strcat/880153)._
