Attached patch fixes a crash when a row fails to refresh
correctly. This can be triggered when the primary key is a timestamp
column with SQLite (because LibO truncates timestamp values and thus
does not find the exact same value back).

-- 
Lionel
>From 236ac0a5948a45b7134066e3f893cb6abdeea3b4 Mon Sep 17 00:00:00 2001
From: Lionel Elie Mamane <lio...@mamane.lu>
Date: Fri, 1 Jun 2012 11:42:53 +0200
Subject: [PATCH] fdo#50372: crash when refresh of last already-known row
 unexpectedly fails

Instead, try to do the least unreasonable thing:
Fetch a new row
If that fails because no new row to fetch, at least we are properly positioned after last row. Calling code may not expect that and get confused, but that is the best we can do.

Change-Id: Ib7248e99ae3deee8344e9386cac2c9440e8bccd8
---
 dbaccess/source/core/api/KeySet.cxx |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/dbaccess/source/core/api/KeySet.cxx b/dbaccess/source/core/api/KeySet.cxx
index cb65fff..101e4a7 100644
--- a/dbaccess/source/core/api/KeySet.cxx
+++ b/dbaccess/source/core/api/KeySet.cxx
@@ -1345,10 +1345,23 @@ void SAL_CALL OKeySet::refreshRow() throw(SQLException, RuntimeException)
     sal_Bool bOK = doTryRefetch_throw();
     if ( !bOK )
     {
+        // This row has disappeared; remove it.
         OKeySetMatrix::iterator aTemp = m_aKeyIter;
+        // use *next* row
         ++m_aKeyIter;
         m_aKeyMap.erase(aTemp);
-        --m_rRowCount;
+
+        // adjust RowCount for the row we have removed
+        if (m_rRowCount > 0)
+            --m_rRowCount;
+        else
+            OSL_FAIL("m_rRowCount got out of sync: non-empty m_aKeyMap, but m_rRowCount <= 0");
+
+        if (!isAfterLast())
+        {
+            // it was the last row, but there may be another one to fetch
+            fetchRow();
+        }
         refreshRow();
     }
     else
-- 
1.7.7.3

_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to