[Groonga-commit] groonga/grnxx at 6ef30a3 [master] Add missing try/catches for memory allocation error handling.

Back to archive index

susumu.yata null+****@clear*****
Tue Dec 2 10:09:05 JST 2014


susumu.yata	2014-12-02 10:09:05 +0900 (Tue, 02 Dec 2014)

  New Revision: 6ef30a3e5967e264f6ab2d6155639b90821b95a0
  https://github.com/groonga/grnxx/commit/6ef30a3e5967e264f6ab2d6155639b90821b95a0

  Message:
    Add missing try/catches for memory allocation error handling.

  Modified files:
    lib/grnxx/impl/index.cpp

  Modified: lib/grnxx/impl/index.cpp (+12 -4)
===================================================================
--- lib/grnxx/impl/index.cpp    2014-12-02 10:06:55 +0900 (89e82b4)
+++ lib/grnxx/impl/index.cpp    2014-12-02 10:09:05 +0900 (4712027)
@@ -64,9 +64,11 @@ template <typename T>
 std::unique_ptr<Cursor> create_exact_match_cursor(T begin,
                                                   T end,
                                                   size_t offset,
-                                                  size_t limit) {
+                                                  size_t limit) try {
   return std::unique_ptr<Cursor>(
       new ExactMatchCursor<T>(begin, end, offset, limit));
+} catch (const std::bad_alloc &) {
+  throw "Memory allocation failed";  // TODO
 }
 
 // TODO: It's not clear that a reverse cursor should return row IDs in
@@ -77,13 +79,15 @@ template <typename T>
 std::unique_ptr<Cursor> create_reverse_exact_match_cursor(T begin,
                                                           T end,
                                                           size_t offset,
-                                                          size_t limit) {
+                                                          size_t limit) try {
   using ReverseIterator = std::reverse_iterator<T>;
   return std::unique_ptr<Cursor>(
       new ExactMatchCursor<ReverseIterator>(ReverseIterator(end),
                                             ReverseIterator(begin),
                                             offset,
                                             limit));
+} catch (const std::bad_alloc &) {
+  throw "Memory allocation failed";  // TODO
 }
 
 // -- ExactMatchCursor --
@@ -162,9 +166,11 @@ template <typename T>
 std::unique_ptr<Cursor> create_range_cursor(T begin,
                                             T end,
                                             size_t offset,
-                                            size_t limit) {
+                                            size_t limit) try {
   return std::unique_ptr<Cursor>(
       new RangeCursor<T>(begin, end, offset, limit));
+} catch (const std::bad_alloc &) {
+  throw "Memory allocation failed";  // TODO
 }
 
 // TODO: It's not clear that a reverse cursor should return row IDs in
@@ -175,13 +181,15 @@ template <typename T>
 std::unique_ptr<Cursor> create_reverse_range_cursor(T begin,
                                                     T end,
                                                     size_t offset,
-                                                    size_t limit) {
+                                                    size_t limit) try {
   using ReverseIterator = std::reverse_iterator<T>;
   return std::unique_ptr<Cursor>(
       new RangeCursor<ReverseIterator>(ReverseIterator(end),
                                        ReverseIterator(begin),
                                        offset,
                                        limit));
+} catch (const std::bad_alloc &) {
+  throw "Memory allocation failed";  // TODO
 }
 
 // -- TreeIndex --
-------------- next part --------------
HTML����������������������������...
Descargar 



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