From 35db39c62aae3da177a063b30ba3434d74a02b90 Mon Sep 17 00:00:00 2001 From: Alexey Andreyev Date: Fri, 20 Aug 2021 10:52:24 +0300 Subject: [PATCH] Fix snprintf usage when geohashing Contributes to github issue #368. --- geohash.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/geohash.c b/geohash.c index ffac1d1..87a54c4 100644 --- a/geohash.c +++ b/geohash.c @@ -112,8 +112,9 @@ char* get_neighbor(char *hash, int direction) { char **border = is_odd ? odd_borders : even_borders; char **neighbor = is_odd ? odd_neighbors : even_neighbors; - char *base = malloc(sizeof(char) * (MAX_GEOHASH_LENGTH + 1)); - snprintf(base, MAX_GEOHASH_LENGTH, "%s", hash); + size_t geohash_b_size = MAX_GEOHASH_LENGTH + 1; + char *base = malloc(sizeof(char) * geohash_b_size); + snprintf(base, geohash_b_size, "%s", hash); if(index_for_char(last_char, border[direction]) != -1) base = get_neighbor(base, direction);