summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2019-10-08 17:02:52 +0200
committerantirez <antirez@gmail.com>2019-10-08 17:09:37 +0200
commit009862ab7eee394061eeaf1aa187fa339ca50be4 (patch)
treeeb0f762c34ad61d22f278223711bd786db07fe08
parentc65347ab17d61a4118efdc4a3568bf71b088ab63 (diff)
downloadredis-009862ab7eee394061eeaf1aa187fa339ca50be4.tar.gz
Geo: output 10 chars of geohash, not 11.
This does not limit the actual precision, because the last digit bits were garbage, and the shift value became even negative in the last iteration.
-rw-r--r--src/geo.c8
-rw-r--r--tests/unit/geo.tcl2
2 files changed, 5 insertions, 5 deletions
diff --git a/src/geo.c b/src/geo.c
index f47f4ee22..049335a4f 100644
--- a/src/geo.c
+++ b/src/geo.c
@@ -734,14 +734,14 @@ void geohashCommand(client *c) {
r[1].max = 90;
geohashEncode(&r[0],&r[1],xy[0],xy[1],26,&hash);
- char buf[12];
+ char buf[11];
int i;
- for (i = 0; i < 11; i++) {
+ for (i = 0; i < 10; i++) {
int idx = (hash.bits >> (52-((i+1)*5))) & 0x1f;
buf[i] = geoalphabet[idx];
}
- buf[11] = '\0';
- addReplyBulkCBuffer(c,buf,11);
+ buf[10] = '\0';
+ addReplyBulkCBuffer(c,buf,10);
}
}
}
diff --git a/tests/unit/geo.tcl b/tests/unit/geo.tcl
index 49e421ee9..76b9bda38 100644
--- a/tests/unit/geo.tcl
+++ b/tests/unit/geo.tcl
@@ -129,7 +129,7 @@ start_server {tags {"geo"}} {
r del points
r geoadd points -5.6 42.6 test
lindex [r geohash points test] 0
- } {ezs42e44yx0}
+ } {ezs42e44yx}
test {GEOPOS simple} {
r del points