Skip to content

Commit

Permalink
[BZ #6007]
Browse files Browse the repository at this point in the history
2008-03-31  Ulrich Drepper  <drepper@redhat.com>
	[BZ #6007]
	* string/strfry.c: Handle empty strings again.
  • Loading branch information
Ulrich Drepper committed Mar 31, 2008
1 parent 4e0b2db commit 3eb9c80
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2008-03-31 Ulrich Drepper <drepper@redhat.com>

[BZ #6007]
* string/strfry.c: Handle empty strings again.

2008-03-30 Ulrich Drepper <drepper@redhat.com>

[BZ #5443]
Expand Down
24 changes: 12 additions & 12 deletions string/strfry.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ strfry (char *string)
{
static int init;
static struct random_data rdata;
size_t len, i;

if (!init)
{
Expand All @@ -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;
}

0 comments on commit 3eb9c80

Please sign in to comment.