[Groonga-commit] groonga/groonga at 5f40db4 [master] grn_ts: detect an error in grn_ts_expr_evaluate()

Back to archive index

susumu.yata null+****@clear*****
Thu Sep 3 11:00:17 JST 2015


susumu.yata	2015-09-03 11:00:17 +0900 (Thu, 03 Sep 2015)

  New Revision: 5f40db437faa92adb0c6d2b6c90a49785f5b6dd3
  https://github.com/groonga/groonga/commit/5f40db437faa92adb0c6d2b6c90a49785f5b6dd3

  Message:
    grn_ts: detect an error in grn_ts_expr_evaluate()
    
    GitHub: #391

  Modified files:
    lib/ts.c

  Modified: lib/ts.c (+33 -8)
===================================================================
--- lib/ts.c    2015-09-02 18:14:40 +0900 (d76559f)
+++ lib/ts.c    2015-09-03 11:00:17 +0900 (321d06c)
@@ -326,6 +326,36 @@ grn_ts_obj_is_column(grn_ctx *ctx, grn_obj *obj) {
   }
 }
 
+/* grn_ts_ja_get_value() appends a value into buf. */
+static grn_rc
+grn_ts_ja_get_value(grn_ctx *ctx, grn_ja *ja, grn_id id,
+                    grn_obj *buf, size_t *value_size) {
+  grn_rc rc, tmp_rc;
+  uint32_t size;
+  grn_io_win iw;
+  char *ptr = (char *)grn_ja_ref(ctx, ja, id, &iw, &size);
+  if (!ptr) {
+    if (value_size) {
+      *value_size = 0;
+    }
+    return GRN_SUCCESS;
+  }
+  rc = grn_bulk_write(ctx, buf, ptr, size);
+  tmp_rc = grn_ja_unref(ctx, &iw);
+  if (rc == GRN_SUCCESS) {
+    if (tmp_rc == GRN_SUCCESS) {
+      if (value_size) {
+        *value_size = size;
+      }
+    } else {
+      /* Discard the value read. */
+      grn_bulk_resize(ctx, buf, GRN_BULK_VSIZE(buf) - size);
+      rc = tmp_rc;
+    }
+  }
+  return rc;
+}
+
 /* grn_ts_table_has_key() returns whether a table has _key or not. */
 static grn_bool
 grn_ts_table_has_key(grn_ctx *ctx, grn_obj *table) {
@@ -1077,20 +1107,15 @@ grn_ts_expr_column_node_evaluate_scalar(grn_ctx *ctx,
     GRN_TS_EXPR_COLUMN_NODE_EVALUATE_SCALAR_CASE_BLOCK(FLOAT, float)
     GRN_TS_EXPR_COLUMN_NODE_EVALUATE_SCALAR_CASE_BLOCK(TIME, time)
     case GRN_TS_TEXT: {
-      size_t i, offset = 0;
+      size_t i, size;
       char *buf_ptr;
       grn_ja *ja = (grn_ja *)node->column;
       grn_ts_text *out_ptr = (grn_ts_text *)out;
       /* Read column values into node->buf and save the size of each value. */
       GRN_BULK_REWIND(&node->buf);
       for (i = 0; i < n_in; i++) {
-        if (grn_ja_get_value(ctx, ja, in[i].id, &node->buf)) {
-          size_t size = GRN_BULK_VSIZE(&node->buf);
-          out_ptr[i].size = size - offset;
-          offset = size;
-        } else {
-          out_ptr[i].size = 0;
-        }
+        grn_rc rc = grn_ts_ja_get_value(ctx, ja, in[i].id, &node->buf, &size);
+        out_ptr[i].size = (rc == GRN_SUCCESS) ? size : 0;
       }
       buf_ptr = GRN_BULK_HEAD(&node->buf);
       for (i = 0; i < n_in; i++) {
-------------- next part --------------
HTML����������������������������...
Télécharger 



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