Date: Monday, March 20, 2006 @ 22:07:43
  Author: marc
    Path: /cvsroot/carob/odbsequoia/src

Modified: util.cpp (1.3 -> 1.4)

Now toSQLW() is also handling an null outsize pointer and an empty buffer.


----------+
 util.cpp |   20 ++++++++++++++++----
 1 files changed, 16 insertions(+), 4 deletions(-)


Index: odbsequoia/src/util.cpp
diff -u odbsequoia/src/util.cpp:1.3 odbsequoia/src/util.cpp:1.4
--- odbsequoia/src/util.cpp:1.3 Thu Jan 19 18:34:08 2006
+++ odbsequoia/src/util.cpp     Mon Mar 20 22:07:43 2006
@@ -91,7 +91,15 @@
 toSQLW(const std::wstring& in,
        SQLWCHAR * const outbuf, const SQLLEN bufsize, SQLLEN * outsize)
 {
-    
+    // no space at all!
+    if (bufsize < 1) {
+        if (outsize)
+            *outsize = 0;
+        // "truncated" since we don't even have the room for the
+        // terminator
+        return true;
+    }
+
     // See explanations in fromSQLW(...) above
     if (sizeof(wchar_t) == sizeof(SQLWCHAR))
     {
@@ -100,8 +108,9 @@
     } else { 
 
     // minus one for the trailing zero. We want enough room for a
-    // SQLWCHAR zero, not just for a byte zero.
-    SQLWCHAR * const outbuf_end = outbuf + bufsize - 1;
+    // SQLWCHAR zero, not just for a byte zero, so be careful with
+    // those parentheses!
+    SQLWCHAR * const outbuf_end = (outbuf + bufsize) - 1;
 
     std::wstring::const_iterator src = in.begin();
     SQLWCHAR * dst = outbuf;
@@ -112,8 +121,11 @@
         dst++; src++;
     }
 
+    // Null terminates the array
     *dst = 0;
-    *outsize = dst - outbuf;
+    
+    if (outsize)
+        *outsize = dst - outbuf;
 
     if (src != in.end())
         return true;

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to