about summary refs log tree commit diff
path: root/wcsmbs/wcsnlen.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-09-23 18:27:55 +0000
committerUlrich Drepper <drepper@redhat.com>2007-09-23 18:27:55 +0000
commit9cc198f65ba914867c8146ab23e0c6adac22a1fb (patch)
treef59086bfae619c6ef493f4bf33069492f05ca56e /wcsmbs/wcsnlen.c
parent27f3d4467d476455a438b825c4edd274fb5b17a8 (diff)
downloadglibc-9cc198f65ba914867c8146ab23e0c6adac22a1fb.tar.gz
glibc-9cc198f65ba914867c8146ab23e0c6adac22a1fb.tar.xz
glibc-9cc198f65ba914867c8146ab23e0c6adac22a1fb.zip
[BZ #4963]
	* wcsmbs/wcsnlen.c: Don't reference before checking the length.
	* string/stratcliff.c: Make usable to test wide char functions.
	* wcsmbs/wcsatcliff.c: New file.
	* wcsmbs/Makefiel (tests): Add wcsatcliff.
Diffstat (limited to 'wcsmbs/wcsnlen.c')
-rw-r--r--wcsmbs/wcsnlen.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/wcsmbs/wcsnlen.c b/wcsmbs/wcsnlen.c
index 3cfbccad91..94abf1e574 100644
--- a/wcsmbs/wcsnlen.c
+++ b/wcsmbs/wcsnlen.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2007 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
 
@@ -28,13 +28,16 @@ __wcsnlen (s, maxlen)
 {
   size_t len = 0;
 
-  while (s[len] != L'\0' && maxlen > 0)
+  while (maxlen > 0 && s[len] != L'\0')
     {
-      if (s[++len] == L'\0' || --maxlen == 0)
+      ++len;
+      if (--maxlen == 0 || s[len] == L'\0')
 	return len;
-      if (s[++len] == L'\0' || --maxlen == 0)
+      ++len;
+      if (--maxlen == 0 || s[len] == L'\0')
 	return len;
-      if (s[++len] == L'\0' || --maxlen == 0)
+      ++len;
+      if (--maxlen == 0 || s[len] == L'\0')
 	return len;
       ++len;
       --maxlen;