Kouhei Sutou
null+****@clear*****
Sat Dec 7 20:33:12 JST 2013
Kouhei Sutou 2013-12-07 20:33:12 +0900 (Sat, 07 Dec 2013) New Revision: d94531e20b9a13a6401b8287de7959b5f2171e9e https://github.com/groonga/groonga/commit/d94531e20b9a13a6401b8287de7959b5f2171e9e Message: geo_in_rectangle: extract data validation code Modified files: lib/geo.c Modified: lib/geo.c (+67 -56) =================================================================== --- lib/geo.c 2013-12-07 20:24:39 +0900 (cd65058) +++ lib/geo.c 2013-12-07 20:33:12 +0900 (b1299bf) @@ -997,6 +997,71 @@ grn_selector_geo_in_rectangle(grn_ctx *ctx, grn_obj *table, grn_obj *index, } static grn_rc +in_rectangle_data_validate(grn_ctx *ctx, + const char *process_name, + in_rectangle_data *data) +{ + grn_geo_point *top_left, *bottom_right; + + top_left = data->top_left; + bottom_right = data->bottom_right; + + if (top_left->latitude < 0 || top_left->longitude < 0 || + bottom_right->latitude < 0 || bottom_right->longitude < 0) { + ERR(GRN_FUNCTION_NOT_IMPLEMENTED, + "%s: negative coordinate is not implemented.", process_name); + goto exit; + } + + if (top_left->latitude >= GRN_GEO_MAX_LATITUDE) { + ERR(GRN_INVALID_ARGUMENT, + "%s: top left point's latitude is too big: " + "<%d>(max:%d): (%d,%d) (%d,%d)", + process_name, + GRN_GEO_MAX_LATITUDE, top_left->latitude, + top_left->latitude, top_left->longitude, + bottom_right->latitude, bottom_right->longitude); + goto exit; + } + + if (top_left->longitude >= GRN_GEO_MAX_LONGITUDE) { + ERR(GRN_INVALID_ARGUMENT, + "%s: top left point's longitude is too big: " + "<%d>(max:%d): (%d,%d) (%d,%d)", + process_name, + GRN_GEO_MAX_LONGITUDE, top_left->longitude, + top_left->latitude, top_left->longitude, + bottom_right->latitude, bottom_right->longitude); + goto exit; + } + + if (bottom_right->latitude >= GRN_GEO_MAX_LATITUDE) { + ERR(GRN_INVALID_ARGUMENT, + "%s: bottom right point's latitude is too big: " + "<%d>(max:%d): (%d,%d) (%d,%d)", + process_name, + GRN_GEO_MAX_LATITUDE, bottom_right->latitude, + top_left->latitude, top_left->longitude, + bottom_right->latitude, bottom_right->longitude); + goto exit; + } + + if (bottom_right->longitude >= GRN_GEO_MAX_LONGITUDE) { + ERR(GRN_INVALID_ARGUMENT, + "%s: bottom right point's longitude is too big: " + "<%d>(max:%d): (%d,%d) (%d,%d)", + process_name, + GRN_GEO_MAX_LONGITUDE, bottom_right->longitude, + top_left->latitude, top_left->longitude, + bottom_right->latitude, bottom_right->longitude); + goto exit; + } + +exit : + return ctx->rc; +} + +static grn_rc in_rectangle_data_prepare(grn_ctx *ctx, grn_obj *index, grn_obj *top_left_point, grn_obj *bottom_right_point, @@ -1051,62 +1116,8 @@ in_rectangle_data_prepare(grn_ctx *ctx, grn_obj *index, } data->bottom_right = GRN_GEO_POINT_VALUE_RAW(bottom_right_point); - { - grn_geo_point *top_left, *bottom_right; - - top_left = data->top_left; - bottom_right = data->bottom_right; - - if (top_left->latitude < 0 || top_left->longitude < 0 || - bottom_right->latitude < 0 || bottom_right->longitude < 0) { - ERR(GRN_FUNCTION_NOT_IMPLEMENTED, - "%s: negative coordinate is not implemented.", process_name); - goto exit; - } - - if (top_left->latitude >= GRN_GEO_MAX_LATITUDE) { - ERR(GRN_INVALID_ARGUMENT, - "%s: top left point's latitude is too big: " - "<%d>(max:%d): (%d,%d) (%d,%d)", - process_name, - GRN_GEO_MAX_LATITUDE, top_left->latitude, - top_left->latitude, top_left->longitude, - bottom_right->latitude, bottom_right->longitude); - goto exit; - } - - if (top_left->longitude >= GRN_GEO_MAX_LONGITUDE) { - ERR(GRN_INVALID_ARGUMENT, - "%s: top left point's longitude is too big: " - "<%d>(max:%d): (%d,%d) (%d,%d)", - process_name, - GRN_GEO_MAX_LONGITUDE, top_left->longitude, - top_left->latitude, top_left->longitude, - bottom_right->latitude, bottom_right->longitude); - goto exit; - } - - if (bottom_right->latitude >= GRN_GEO_MAX_LATITUDE) { - ERR(GRN_INVALID_ARGUMENT, - "%s: bottom right point's latitude is too big: " - "<%d>(max:%d): (%d,%d) (%d,%d)", - process_name, - GRN_GEO_MAX_LATITUDE, bottom_right->latitude, - top_left->latitude, top_left->longitude, - bottom_right->latitude, bottom_right->longitude); - goto exit; - } - - if (bottom_right->longitude >= GRN_GEO_MAX_LONGITUDE) { - ERR(GRN_INVALID_ARGUMENT, - "%s: bottom right point's longitude is too big: " - "<%d>(max:%d): (%d,%d) (%d,%d)", - process_name, - GRN_GEO_MAX_LONGITUDE, bottom_right->longitude, - top_left->latitude, top_left->longitude, - bottom_right->latitude, bottom_right->longitude); - goto exit; - } + if (in_rectangle_data_validate(ctx, process_name, data) != GRN_SUCCESS) { + goto exit; } { -------------- next part -------------- HTML����������������������������...Download