diff --git a/src/common.c b/src/common.c index eca444e6..6020b8c3 100644 --- a/src/common.c +++ b/src/common.c @@ -441,13 +441,14 @@ get_random_string(int length) GRand* prng; char* rand; char alphabet[] = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; + int endrange = sizeof(alphabet) - 1; rand = calloc(length + 1, sizeof(char)); prng = g_rand_new(); for (int i = 0; i < length; i++) { - rand[i] = alphabet[g_rand_int_range(prng, 0, sizeof(alphabet))]; + rand[i] = alphabet[g_rand_int_range(prng, 0, endrange)]; } g_rand_free(prng);