diff options
author | Jakub Jelinek <jakub@redhat.com> | 2008-04-08 07:59:52 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2008-04-08 07:59:52 +0000 |
commit | e6e467b8352b6a62b8187fd241671eb55d0f6fc4 (patch) | |
tree | 2e7c2ddae1aa58a70c384e1d5b49d3ad198a2718 /string/strfry.c | |
parent | 09b731ac2b1b5e79050991f6a9dab964f9a7a60f (diff) | |
download | glibc-e6e467b8352b6a62b8187fd241671eb55d0f6fc4.tar.gz glibc-e6e467b8352b6a62b8187fd241671eb55d0f6fc4.tar.xz glibc-e6e467b8352b6a62b8187fd241671eb55d0f6fc4.zip |
Updated to fedora-glibc-20080408T0706
Diffstat (limited to 'string/strfry.c')
-rw-r--r-- | string/strfry.c | 24 |
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; } |