From: Ulrich Drepper Date: Mon, 31 Mar 2008 18:30:26 +0000 (+0000) Subject: [BZ #6007] X-Git-Tag: upstream/2.30~14305 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3eb9c80984fa8ffa1bba570b34c380bbfd2a0258;p=external%2Fglibc.git [BZ #6007] 2008-03-31 Ulrich Drepper [BZ #6007] * string/strfry.c: Handle empty strings again. --- diff --git a/ChangeLog b/ChangeLog index 52f4456..2cf9f3c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-03-31 Ulrich Drepper + + [BZ #6007] + * string/strfry.c: Handle empty strings again. + 2008-03-30 Ulrich Drepper [BZ #5443] diff --git a/string/strfry.c b/string/strfry.c index d392d55..d3fcb14 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; }