]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix for the following:
authorJulian Seward <jseward@acm.org>
Wed, 21 Aug 2002 22:29:14 +0000 (22:29 +0000)
committerJulian Seward <jseward@acm.org>
Wed, 21 Aug 2002 22:29:14 +0000 (22:29 +0000)
vg_mylibc:VG_(strncpy)() behaves dubiously -- it can write a
'\0' past the end of the given array.

Possibly accounting for some strange behaviour in the g++3 demangler?

git-svn-id: svn://svn.valgrind.org/valgrind/branches/VALGRIND_1_0_BRANCH@613

vg_mylibc.c

index da63d4c2e80f7a13554064348562f65304ea76d1..38f5a3dd4261b8fb0a52c6e1f49e601cf47b1dfb 100644 (file)
@@ -765,7 +765,13 @@ void VG_(strncpy_safely) ( Char* dest, const Char* src, Int ndest )
 
 void VG_(strncpy) ( Char* dest, const Char* src, Int ndest )
 {
-   VG_(strncpy_safely)( dest, src, ndest+1 ); 
+   Int i = 0;
+   while (True) {
+      if (src[i] == 0) return;
+      if (i >= ndest) return;
+      dest[i] = src[i];
+      i++;
+   }
 }