From 0016bcee374606e79c48a1a97479b0521f947942 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Tue, 19 Oct 2010 23:07:49 +0200 Subject: klogd: do not log partial lines function old new delta overlapping_strcpy 15 18 +3 klogd_main 438 436 -2 Signed-off-by: Denys Vlasenko --- libbb/safe_strncpy.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'libbb/safe_strncpy.c') diff --git a/libbb/safe_strncpy.c b/libbb/safe_strncpy.c index 8eb6a014f..5eb0db0bd 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++; + } } } -- cgit v1.2.3