fix s_strncpy bug 02/11002/2
authorho.namkoong <ho.namkoong@samsung.com>
Wed, 16 Oct 2013 04:58:32 +0000 (13:58 +0900)
committerho.namkoong <ho.namkoong@samsung.com>
Thu, 17 Oct 2013 02:20:18 +0000 (11:20 +0900)
Change-Id: Ibc6d487edf4173e5484daae8130982c813c1facb

src/strutils.c

index 2823e1222b341fa25adf47474fbc0a753cd0b0bd..33bff63b2fc2258e1b946d95684cea2ce809017d 100644 (file)
@@ -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;
 }