Hi all

I got crash in my program that uses SOCI 3.1.0. The problem is that
sometime, get_number_of_rows can return negative value, and in my case
it lead to crash when trying to resize vector. I attached the patch
that should fix this, and if it's ok, then I can commit it to
github.com:soci-project/soci

-- 
With best wishes,                    Alex Ott
http://alexott.net/
Tiwtter: alexott_en (English), alexott (Russian)
Skype: alex.ott
From e3a427160dd2515fc1b2aca159749d4d021c5770 Mon Sep 17 00:00:00 2001
From: Alex Ott <[email protected]>
Date: Mon, 20 Feb 2012 11:40:16 +0100
Subject: [PATCH] correctly handle negative values

sometimes, get_number_of_rows can return negative value, and this could lead to crash when
trying to resize vector
---
 src/core/statement.cpp |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/core/statement.cpp b/src/core/statement.cpp
index 582a6a9..8d2a3b6 100644
--- a/src/core/statement.cpp
+++ b/src/core/statement.cpp
@@ -495,16 +495,20 @@ bool statement_impl::resize_intos(std::size_t upperBound)
     // this function does not need to take into account the intosForRow_
     // elements, since they are never used for bulk operations
 
-    std::size_t rows = backEnd_->get_number_of_rows();
-    if (upperBound != 0 && upperBound < rows)
+	int rows = backEnd_->get_number_of_rows();
+	if (rows < 0)
+	{
+		rows = 0;
+	}
+    if (upperBound != 0 && upperBound < (std::size_t)rows)
     {
-        rows = upperBound;
+        rows = (int)upperBound;
     }
 
     std::size_t const isize = intos_.size();
     for (std::size_t i = 0; i != isize; ++i)
     {
-        intos_[i]->resize(rows);
+        intos_[i]->resize((std::size_t)rows);
     }
 
     return rows > 0 ? true : false;
-- 
1.7.9

------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to