[Groonga-commit] groonga/groonga [master] Fix a bug that -4 -> 4294967292 for UInt32

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Mar 6 11:44:31 JST 2013


Kouhei Sutou	2013-03-06 11:44:31 +0900 (Wed, 06 Mar 2013)

  New Revision: c45e8972ff737135dae4a1fc98c2848fdbdbcc04
  https://github.com/groonga/groonga/commit/c45e8972ff737135dae4a1fc98c2848fdbdbcc04

  Log:
    Fix a bug that -4 -> 4294967292 for UInt32
    
    We should cast to more larger signed integer size before "-"
    operation.

  Added files:
    test/command/suite/select/filter/arithmetic_operation/unary_minus/uint32.expected
    test/command/suite/select/filter/arithmetic_operation/unary_minus/uint32.test
  Modified files:
    lib/expr.c

  Modified: lib/expr.c (+1 -1)
===================================================================
--- lib/expr.c    2013-03-05 18:31:09 +0900 (e7aa765)
+++ lib/expr.c    2013-03-06 11:44:31 +0900 (634de7a)
@@ -2260,7 +2260,7 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
     break;                                                              \
   case GRN_DB_UINT32 :                                                  \
     {                                                                   \
-      unsigned int x_;                                                  \
+      long long int x_;                                                 \
       x_ = GRN_UINT32_VALUE(x);                                         \
       left_expression_check(x_);                                        \
       GRN_INT64_SET(ctx, res, integer_operation(x_));                   \

  Added: test/command/suite/select/filter/arithmetic_operation/unary_minus/uint32.expected (+11 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/arithmetic_operation/unary_minus/uint32.expected    2013-03-06 11:44:31 +0900 (da9bea3)
@@ -0,0 +1,11 @@
+table_create Values TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Values value COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+load --table Values
+[
+{"value": 1}
+]
+[[0,0.0,0.0],1]
+select Values   --filter true   --scorer '_score = -value'   --output_columns 'value, _score'
+[[0,0.0,0.0],[[[1],[["value","UInt32"],["_score","Int32"]],[1,-1]]]]

  Added: test/command/suite/select/filter/arithmetic_operation/unary_minus/uint32.test (+12 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/filter/arithmetic_operation/unary_minus/uint32.test    2013-03-06 11:44:31 +0900 (7ae9713)
@@ -0,0 +1,12 @@
+table_create Values TABLE_NO_KEY
+column_create Values value COLUMN_SCALAR UInt32
+
+load --table Values
+[
+{"value": 1}
+]
+
+select Values \
+  --filter true \
+  --scorer '_score = -value' \
+  --output_columns 'value, _score'
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index