aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-26 13:09:47 +0100
committerMattias Andrée <maandree@kth.se>2016-03-26 13:09:47 +0100
commit3b5b6f89026d437b8bcdb9384d053e42095c883a (patch)
tree49784112fd92d52754bb3b1eecade99402fc0f4e /src
parentFix issue #11 on github (diff)
downloadslibc-3b5b6f89026d437b8bcdb9384d053e42095c883a.tar.gz
slibc-3b5b6f89026d437b8bcdb9384d053e42095c883a.tar.bz2
slibc-3b5b6f89026d437b8bcdb9384d053e42095c883a.tar.xz
strfry: fix support for empty strings
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--src/string/strfry.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/string/strfry.c b/src/string/strfry.c
index b46fb06..aa09d0b 100644
--- a/src/string/strfry.c
+++ b/src/string/strfry.c
@@ -35,12 +35,13 @@
*/
char* strfry(char* anagram)
{
- size_t i, j;
+ size_t i, j, n;
int r;
char t;
if (anagram == NULL)
return NULL;
- for (i = strlen(anagram) - 1; i; i--)
+ n = strlen(anagram);
+ for (i = n - 1; n && i; i--)
{
r = rand();
j = (size_t)((double)r / ((double)RAND_MAX + 1) * (double)i); /* TODO This is not uniformally random. */