null+****@clear*****
null+****@clear*****
2011年 3月 10日 (木) 17:14:54 JST
Kouhei Sutou 2011-03-10 08:14:54 +0000 (Thu, 10 Mar 2011)
New Revision: b22c78d84df25d403d6ec8fe144ccb65201ff0f9
Log:
fix crash by passing same locations to geo_in_rectangle().
Modified files:
lib/geo.c
test/unit/story/test-taiyaki.c
Modified: lib/geo.c (+2 -1)
===================================================================
--- lib/geo.c 2011-03-10 07:54:31 +0000 (19fb0d3)
+++ lib/geo.c 2011-03-10 08:14:54 +0000 (8a797b2)
@@ -37,10 +37,11 @@ typedef struct
static int
compute_diff_bit(uint8_t *geo_key1, uint8_t *geo_key2)
{
- int i, j, diff_bit = 8;
+ int i, j, diff_bit = 0;
for (i = 0; i < sizeof(grn_geo_point); i++) {
if (geo_key1[i] != geo_key2[i]) {
+ diff_bit = 8;
for (j = 0; j < 8; j++) {
if ((geo_key1[i] & (1 << (7 - j))) != (geo_key2[i] & (1 << (7 - j)))) {
diff_bit = j;
Modified: test/unit/story/test-taiyaki.c (+28 -0)
===================================================================
--- test/unit/story/test-taiyaki.c 2011-03-10 07:54:31 +0000 (1375941)
+++ test/unit/story/test-taiyaki.c 2011-03-10 08:14:54 +0000 (80167c6)
@@ -24,6 +24,7 @@
void test_in_circle(void);
void test_in_rectangle_long_latitude(void);
void test_in_rectangle_long_longitude(void);
+void test_in_rectangle_same_locations(void);
void test_in_rectangle_over_border(void);
void test_in_rectangle_over_latitude1(void);
void test_in_rectangle_over_longitude1(void);
@@ -195,6 +196,33 @@ test_in_rectangle_long_longitude(void)
}
void
+test_in_rectangle_same_locations(void)
+{
+ gdouble takada_no_baba_latitude = 35.7121;
+ gdouble takada_no_baba_longitude = 139.7038;
+ gdouble budoukan_latitude = 35.69328;
+ gdouble budoukan_longitude = 139.74968;
+
+ cut_assert_equal_string(
+ "[[[0],"
+ "[[\"name\",\"ShortText\"],[\"_score\",\"Int32\"],"
+ "[\"location\",\"WGS84GeoPoint\"]]"
+ "]]",
+ send_command(
+ cut_take_printf(
+ "select Shops "
+ "--sortby '+_score, +name' "
+ "--output_columns 'name, _score, location' "
+ "--filter 'geo_in_rectangle(location, \"%s\", \"%s\")' "
+ "--scorer '_score=geo_distance(location, \"%s\")'",
+ grn_test_location_string(takada_no_baba_latitude,
+ takada_no_baba_longitude),
+ grn_test_location_string(takada_no_baba_latitude,
+ takada_no_baba_longitude),
+ grn_test_location_string(budoukan_latitude, budoukan_longitude))));
+}
+
+void
test_in_rectangle_over_border(void)
{
grn_test_assert_send_command_error(