about summary refs log tree commit diff
path: root/string
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2008-03-31 18:30:26 +0000
committerUlrich Drepper <drepper@redhat.com>2008-03-31 18:30:26 +0000
commit3eb9c80984fa8ffa1bba570b34c380bbfd2a0258 (patch)
tree0d00190a9a2387acc0c3f83579a753883c491fdf /string
parent4e0b2dbe548876b86fcb7067f2e7f6ff7a9eedc6 (diff)
downloadglibc-3eb9c80984fa8ffa1bba570b34c380bbfd2a0258.tar.gz
glibc-3eb9c80984fa8ffa1bba570b34c380bbfd2a0258.tar.xz
glibc-3eb9c80984fa8ffa1bba570b34c380bbfd2a0258.zip
[BZ #6007]
2008-03-31  Ulrich Drepper  <drepper@redhat.com>
	[BZ #6007]
	* string/strfry.c: Handle empty strings again.
Diffstat (limited to 'string')
-rw-r--r--string/strfry.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/string/strfry.c b/string/strfry.c
index d392d5526b..d3fcb14bab 100644
--- a/string/strfry.c
+++ b/string/strfry.c
@@ -26,7 +26,6 @@ strfry (char *string)
 {
   static int init;
   static struct random_data rdata;
-  size_t len, i;
 
   if (!init)
     {
@@ -37,17 +36,18 @@ strfry (char *string)
       init = 1;
     }
 
-  len = strlen (string) - 1;
-  for (i = 0; i < len; ++i)
-    {
-      int32_t j;
-      __random_r (&rdata, &j);
-      j = j % (len - i) + i;
-
-      char c = string[i];
-      string[i] = string[j];
-      string[j] = c;
-    }
+  size_t len = strlen (string);
+  if (len > 0)
+    for (size_t i = 0; i < len - 1; ++i)
+      {
+	int32_t j;
+	__random_r (&rdata, &j);
+	j = j % (len - i) + i;
+
+	char c = string[i];
+	string[i] = string[j];
+	string[j] = c;
+      }
 
   return string;
 }