Hello 

I traced it down to wrong limit checking in common.h. Attached is a patch to 
fix it. It seems that it is not yet fixed in the git repo.

The patch also includes other minor fixes I had to make to get soci compiled 
on archlinux x86_64.

Why does postgresql backend uses sscanf which is not type-safe and mysql uses 
stringstream which is type safe?

-- 
 Shridhar
diff -bBur soci-3.0.0/src/backends/mysql/common.h soci-3.0.0.changed/src/backends/mysql/common.h
--- soci-3.0.0/src/backends/mysql/common.h	2008-07-03 12:52:57.000000000 +0530
+++ soci-3.0.0.changed/src/backends/mysql/common.h	2010-01-08 21:43:09.585997152 +0530
@@ -9,6 +9,7 @@
 #define SOCI_MYSQL_COMMON_H_INCLUDED

 #include <sstream>
+#include <ctime>
 #include "soci-mysql.h"

 namespace soci
diff -bBur soci-3.0.0/src/backends/mysql/session.cpp soci-3.0.0.changed/src/backends/mysql/session.cpp
--- soci-3.0.0/src/backends/mysql/session.cpp	2008-05-15 19:28:38.000000000 +0530
+++ soci-3.0.0.changed/src/backends/mysql/session.cpp	2010-01-08 21:43:09.429330724 +0530
@@ -11,7 +11,8 @@
 #include <cctype>
 #include <cerrno>
 #include <ciso646>
-
+#include <cstdlib>
+#include <climits>

 #ifdef _MSC_VER
 #pragma warning(disable:4355)
diff -bBur soci-3.0.0/src/backends/mysql/standard-into-type.cpp soci-3.0.0.changed/src/backends/mysql/standard-into-type.cpp
--- soci-3.0.0/src/backends/mysql/standard-into-type.cpp	2008-05-30 17:03:45.000000000 +0530
+++ soci-3.0.0.changed/src/backends/mysql/standard-into-type.cpp	2010-01-08 21:43:09.532663960 +0530
@@ -12,6 +12,7 @@
 #include "common.h"
 #include <ciso646>
 #include <cassert>
+#include <cstring>

 #ifdef _MSC_VER
 #pragma warning(disable:4355)
diff -bBur soci-3.0.0/src/backends/mysql/standard-use-type.cpp soci-3.0.0.changed/src/backends/mysql/standard-use-type.cpp
--- soci-3.0.0/src/backends/mysql/standard-use-type.cpp	2008-05-15 19:28:38.000000000 +0530
+++ soci-3.0.0.changed/src/backends/mysql/standard-use-type.cpp	2010-01-08 21:43:09.372664079 +0530
@@ -13,6 +13,8 @@
 #include <ciso646>
 #include <limits>
 #include <cstring>
+#include <cstdio>
+#include <ctime>

 #ifdef _MSC_VER
 #pragma warning(disable:4355)
diff -bBur soci-3.0.0/src/backends/mysql/vector-use-type.cpp soci-3.0.0.changed/src/backends/mysql/vector-use-type.cpp
--- soci-3.0.0/src/backends/mysql/vector-use-type.cpp	2008-05-15 19:28:38.000000000 +0530
+++ soci-3.0.0.changed/src/backends/mysql/vector-use-type.cpp	2010-01-08 21:43:09.523104803 +0530
@@ -12,6 +12,7 @@
 #include <soci-platform.h>
 #include <ciso646>
 #include <limits>
+#include <cstdio>
 #include <cstring>

 #ifdef _MSC_VER
diff -bBur soci-3.0.0/src/backends/postgresql/common.h soci-3.0.0.changed/src/backends/postgresql/common.h
--- soci-3.0.0/src/backends/postgresql/common.h	2008-07-04 18:27:54.000000000 +0530
+++ soci-3.0.0.changed/src/backends/postgresql/common.h	2010-01-17 11:45:43.305737410 +0530
@@ -36,10 +36,12 @@

         const T max = (std::numeric_limits<T>::max)();
         const T min = (std::numeric_limits<T>::min)();
-        if (t <= static_cast<long long>(max) &&
-            t >= static_cast<long long>(min))
+
+		T retval = static_cast<T>(t);
+
+        if (retval <= max && t >= min)
         {
-            return static_cast<T>(t);
+            return retval;
         }
         else
         {
diff -bBur soci-3.0.0/src/core/soci-simple.cpp soci-3.0.0.changed/src/core/soci-simple.cpp
--- soci-3.0.0/src/core/soci-simple.cpp	2008-07-01 13:12:25.000000000 +0530
+++ soci-3.0.0.changed/src/core/soci-simple.cpp	2010-01-08 21:43:10.059330522 +0530
@@ -9,6 +9,7 @@

 #include "soci-simple.h"
 #include "soci.h"
+#include <cstdio>

 using namespace soci;

------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Soci-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/soci-users

Reply via email to