[Groonga-commit] groonga/grnxx at 02b451f [master] Add error handling in Table::reserve_bit().

Back to archive index

susumu.yata null+****@clear*****
Fri Aug 1 11:00:25 JST 2014


susumu.yata	2014-08-01 11:00:25 +0900 (Fri, 01 Aug 2014)

  New Revision: 02b451f108da42bf0041f76f05046194071131f5
  https://github.com/groonga/grnxx/commit/02b451f108da42bf0041f76f05046194071131f5

  Message:
    Add error handling in Table::reserve_bit().

  Modified files:
    lib/grnxx/table.cpp

  Modified: lib/grnxx/table.cpp (+13 -8)
===================================================================
--- lib/grnxx/table.cpp    2014-08-01 10:09:14 +0900 (f6206fc)
+++ lib/grnxx/table.cpp    2014-08-01 11:00:25 +0900 (f5aa9ba)
@@ -543,25 +543,30 @@ bool Table::reserve_bit(Error *error, Int i) {
     GRNXX_ERROR_SET(error, INVALID_ARGUMENT, "Invalid argument");
     return false;
   }
-  // TODO: Error handling.
+  // Resize the bitmap if required.
   size_t block_id = i / 64;
   if (block_id >= bitmap_.size()) {
-    bitmap_.resize(error, block_id + 1, 0);
+    if (!bitmap_.resize(error, block_id + 1, 0)) {
+      return false;
+    }
   }
+  // Resize the existing bitmap indexes if required.
   for (Int index_id = 0; index_id < bitmap_indexes_.size(); ++index_id) {
     block_id /= 64;
     if (block_id >= bitmap_indexes_[index_id].size()) {
-      bitmap_indexes_[index_id].resize(error, block_id + 1, 0);
-    } else {
-      block_id = 0;
-      break;
+      if (!bitmap_indexes_[index_id].resize(error, block_id + 1, 0)) {
+        return false;
+      }
     }
   }
+  // Add bitmap indexes if requires.
   Int depth = bitmap_indexes_.size();
   while (block_id > 0) {
     block_id /= 64;
-    bitmap_indexes_.resize(error, depth + 1);
-    bitmap_indexes_[depth].resize(error, block_id + 1, 0);
+    if (!bitmap_indexes_.resize(error, depth + 1) ||
+        !bitmap_indexes_[depth].resize(error, block_id + 1, 0)) {
+      return false;
+    }
     if (depth == 0) {
       bitmap_indexes_[depth][0] = bitmap_[0] != 0;
     } else {
-------------- next part --------------
HTML����������������������������...
Download 



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