From: ho.namkoong Date: Wed, 16 Oct 2013 04:58:32 +0000 (+0900) Subject: fix s_strncpy bug X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=edf29124b0f08c5da2b6e38327edb97249843d43;p=sdk%2Ftools%2Fsdb.git fix s_strncpy bug Change-Id: Ibc6d487edf4173e5484daae8130982c813c1facb --- diff --git a/src/strutils.c b/src/strutils.c index 2823e12..33bff63 100644 --- a/src/strutils.c +++ b/src/strutils.c @@ -69,15 +69,18 @@ int read_line(const int fd, char* ptr, const unsigned int maxlen) * ntbs[sizeof(ntbs)-1] = '\0' */ char *s_strncpy(char *dest, const char *source, size_t n) { + char *start = dest; - while (n && (*dest++ = *source++)) { - n--; - } - if (n) { - while (--n) { - *dest++ = '\0'; + if(n) { + while(--n) { + if(*source == '\0') { + break; + } + *dest++ = *source++; } } + + *dest = '\0'; return start; }