Fix strncpy usage when geohashing

Contributes to github issue #368.
This commit is contained in:
Alexey Andreyev
2021-08-19 16:41:24 +03:00
parent 8c6c6092b3
commit ede524a77d
+9 -3
View File
@@ -47,6 +47,13 @@
#define LENGTH_OF_DEGREE 111100 // meters
/*
* From Elasticsearch Guide:
* The highest-precision geohash of length 12 produces cells
* that cover less than a square metre of land.
*/
#define MAX_GEOHASH_LENGTH 12
typedef struct IntervalStruct {
double high;
@@ -105,9 +112,8 @@ 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) * 1);
base[0] = '\0';
strncat(base, hash, hash_length - 1);
char *base = malloc(sizeof(char) * (MAX_GEOHASH_LENGTH + 1));
snprintf(base, MAX_GEOHASH_LENGTH, "%s", hash);
if(index_for_char(last_char, border[direction]) != -1)
base = get_neighbor(base, direction);