diff options
author | Mattias Andrée <maandree@kth.se> | 2016-03-26 13:09:47 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2016-03-26 13:09:47 +0100 |
commit | 3b5b6f89026d437b8bcdb9384d053e42095c883a (patch) | |
tree | 49784112fd92d52754bb3b1eecade99402fc0f4e | |
parent | Fix issue #11 on github (diff) | |
download | slibc-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>
-rw-r--r-- | src/string/strfry.c | 5 |
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. */ |