Author: wyoung
Date: Fri May 2 17:14:17 2008
New Revision: 2283
URL: http://svn.gna.org/viewcvs/mysqlpp?rev=2283&view=rev
Log:
Fixed mysqlpp::String comparisons of empty strings against nonempty
strings; if the empty string was on the left hand side, it would succeed
because it was only comparing against characters in the empty side,
which matches everything. (Fixes bug 11588.)
Modified:
trunk/lib/mystring.cpp
trunk/test/string.cpp
Modified: trunk/lib/mystring.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/lib/mystring.cpp?rev=2283&r1=2282&r2=2283&view=diff
==============================================================================
--- trunk/lib/mystring.cpp (original)
+++ trunk/lib/mystring.cpp Fri May 2 17:14:17 2008
@@ -2,7 +2,7 @@
mystring.cpp - Implements the String class.
Copyright (c) 1998 by Kevin Atkinson, (c) 1999-2001 by MySQL AB, and
- (c) 2004-2007 by Educational Technology Resources, Inc. Others may
+ (c) 2004-2008 by Educational Technology Resources, Inc. Others may
also hold copyrights on code in this file. See the CREDITS file in
the top directory of the distribution for details.
@@ -27,6 +27,7 @@
#include "mystring.h"
#include "query.h"
+#include <algorithm>
#include <stdexcept>
#include <string>
@@ -49,7 +50,8 @@
String::compare(const String& other) const
{
if (other.buffer_) {
- return compare(0, length(), other.buffer_->data());
+ return compare(0, std::max(length(), other.length()),
+ other.buffer_->data());
}
else {
// Other object has no buffer, so we are greater unless empty or
@@ -62,7 +64,7 @@
int
String::compare(const std::string& other) const
{
- return compare(0, length(), other.data());
+ return compare(0, std::max(length(), other.length()), other.data());
}
@@ -76,7 +78,7 @@
int
String::compare(const char* other) const
{
- return compare(0, length(), other);
+ return compare(0, std::max(length(), strlen(other)), other);
}
Modified: trunk/test/string.cpp
URL:
http://svn.gna.org/viewcvs/mysqlpp/trunk/test/string.cpp?rev=2283&r1=2282&r2=2283&view=diff
==============================================================================
--- trunk/test/string.cpp (original)
+++ trunk/test/string.cpp Fri May 2 17:14:17 2008
@@ -291,6 +291,7 @@
failures += test_string_equality(zero, "0") == false;
failures += test_string_inequality(definit, zero) == false;
failures += test_string_inequality(zero, definit) == false;
+ failures += test_string_inequality(empty, nonzero) == false;
return failures;
}
_______________________________________________
Mysqlpp-commits mailing list
[email protected]
https://mail.gna.org/listinfo/mysqlpp-commits