[Groonga-mysql-commit] mroonga/mroonga at 0234c47 [master] multiple column key: fix a potential bug that decoding value is broken

Back to archive index

Kouhei Sutou null+****@clear*****
Fri May 15 12:05:02 JST 2015


Kouhei Sutou	2015-05-15 12:05:02 +0900 (Fri, 15 May 2015)

  New Revision: 0234c47fdb454c73bcf93a7df00056a0e24df2fb
  https://github.com/mroonga/mroonga/commit/0234c47fdb454c73bcf93a7df00056a0e24df2fb

  Message:
    multiple column key: fix a potential bug that decoding value is broken
    
    We should use network byte order -> host byte order conversion on
    decoding because we use host byte order -> network byte order conversion
    on encoding.

  Modified files:
    lib/mrn_multiple_column_key_codec.cpp

  Modified: lib/mrn_multiple_column_key_codec.cpp (+17 -3)
===================================================================
--- lib/mrn_multiple_column_key_codec.cpp    2015-05-15 00:09:27 +0900 (f79c7cc)
+++ lib/mrn_multiple_column_key_codec.cpp    2015-05-15 12:05:02 +0900 (1a109e9)
@@ -37,6 +37,13 @@
   uint8 *key_ = (uint8 *)(key);                         \
   while (size_--) { *buf_++ = *key_++; }                \
 }
+#define mrn_byte_order_network_to_host(buf, key, size)  \
+{                                                       \
+  uint32 size_ = (uint32_t)(size);                      \
+  uint8 *buf_ = (uint8_t *)(buf);                       \
+  uint8 *key_ = (uint8_t *)(key);                       \
+  while (size_) { *buf_++ = *key_++; size_--; }         \
+}
 #else /* WORDS_BIGENDIAN */
 #define mrn_byte_order_host_to_network(buf, key, size)  \
 {                                                       \
@@ -45,6 +52,13 @@
   uint8 *key_ = (uint8 *)(key) + size_;                 \
   while (size_--) { *buf_++ = *(--key_); }              \
 }
+#define mrn_byte_order_network_to_host(buf, key, size)  \
+{                                                       \
+  uint32 size_ = (uint32)(size);                        \
+  uint8 *buf_ = (uint8 *)(buf);                         \
+  uint8 *key_ = (uint8 *)(key) + size_;                 \
+  while (size_) { *buf_++ = *(--key_); size_--; }       \
+}
 #endif /* WORDS_BIGENDIAN */
 
 namespace mrn {
@@ -472,7 +486,7 @@ namespace mrn {
     uchar buffer[8];
     memcpy(buffer, grn_key, data_size);
     *((uint8 *)(buffer)) ^= 0x80;
-    mrn_byte_order_host_to_network(value, buffer, data_size);
+    mrn_byte_order_network_to_host(value, buffer, data_size);
     DBUG_VOID_RETURN;
   }
 
@@ -492,7 +506,7 @@ namespace mrn {
                                             uint data_size) {
     MRN_DBUG_ENTER_METHOD();
     int int_value;
-    mrn_byte_order_host_to_network(&int_value, grn_key, data_size);
+    mrn_byte_order_network_to_host(&int_value, grn_key, data_size);
     int max_bit = (data_size * 8 - 1);
     *((int *)mysql_key) =
       int_value ^ (((int_value ^ (1 << max_bit)) >> max_bit) |
@@ -516,7 +530,7 @@ namespace mrn {
                                              uint data_size) {
     MRN_DBUG_ENTER_METHOD();
     long long int long_long_value;
-    mrn_byte_order_host_to_network(&long_long_value, grn_key, data_size);
+    mrn_byte_order_network_to_host(&long_long_value, grn_key, data_size);
     int max_bit = (data_size * 8 - 1);
     *((long long int *)mysql_key) =
       long_long_value ^ (((long_long_value ^ (1LL << max_bit)) >> max_bit) |
-------------- next part --------------
HTML����������������������������...
下載 



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