summaryrefslogtreecommitdiff
path: root/libbb/safe_strncpy.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/safe_strncpy.c')
-rw-r--r--libbb/safe_strncpy.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/libbb/safe_strncpy.c b/libbb/safe_strncpy.c
index 8eb6a01..5eb0db0 100644
--- a/libbb/safe_strncpy.c
+++ b/libbb/safe_strncpy.c
@@ -20,8 +20,13 @@ char* FAST_FUNC safe_strncpy(char *dst, const char *src, size_t size)
/* Like strcpy but can copy overlapping strings. */
void FAST_FUNC overlapping_strcpy(char *dst, const char *src)
{
- while ((*dst = *src) != '\0') {
- dst++;
- src++;
+ /* Cheap optimization for dst == src case -
+ * better to have it here than in many callers.
+ */
+ if (dst != src) {
+ while ((*dst = *src) != '\0') {
+ dst++;
+ src++;
+ }
}
}