From 5a72c5058c27cdc778cde8f61d16691b11a6adc5 Mon Sep 17 00:00:00 2001 From: antirez Date: Wed, 18 Dec 2019 12:57:32 +0100 Subject: Fix GEOHASH negative shifting in a more compatible way. --- src/geo.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/geo.c') diff --git a/src/geo.c b/src/geo.c index f47f4ee22..f7920a2e2 100644 --- a/src/geo.c +++ b/src/geo.c @@ -737,7 +737,15 @@ void geohashCommand(client *c) { char buf[12]; int i; for (i = 0; i < 11; i++) { - int idx = (hash.bits >> (52-((i+1)*5))) & 0x1f; + int idx; + if (i == 10) { + /* We have just 52 bits, but the API used to output + * an 11 bytes geohash. For compatibility we assume + * zero. */ + idx = 0; + } else { + idx = (hash.bits >> (52-((i+1)*5))) & 0x1f; + } buf[i] = geoalphabet[idx]; } buf[11] = '\0'; -- cgit v1.2.1