[nemiver] Make sure Addresses are valid
- From: Dodji Seketeli <dodji src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nemiver] Make sure Addresses are valid
- Date: Sat, 17 Jul 2010 21:33:42 +0000 (UTC)
commit 9ac347f3192dea8e0c90df125a222e2b10d496c9
Author: Dodji Seketeli <dodji gnome org>
Date: Tue Apr 27 15:23:15 2010 +0200
Make sure Addresses are valid
* src/common/nmv-address.cc (Address::operator=,
Address::Address(const string&)): Validate the
the address string.
src/common/nmv-address.cc | 24 +++++++++++++++++++-----
1 files changed, 19 insertions(+), 5 deletions(-)
---
diff --git a/src/common/nmv-address.cc b/src/common/nmv-address.cc
index bcab3a7..68c2bbd 100644
--- a/src/common/nmv-address.cc
+++ b/src/common/nmv-address.cc
@@ -24,6 +24,7 @@
*/
#include "nmv-address.h"
#include "nmv-str-utils.h"
+#include "nmv-exception.h"
NEMIVER_BEGIN_NAMESPACE (nemiver)
NEMIVER_BEGIN_NAMESPACE (common)
@@ -32,10 +33,16 @@ Address::Address ()
{
}
-Address::Address (const std::string &a) :
- m_addr (a)
+Address::Address (const std::string &a)
{
- str_utils::chomp (m_addr);
+ string str = a;
+ str_utils::chomp (str);
+ if (!str.empty () && !str_utils::string_is_number (str)) {
+ stringstream msg;
+ msg << "Invalid address format: " << str;
+ THROW (msg.str ());
+ }
+ m_addr = str;
}
Address::Address (const Address &a_other) :
@@ -83,8 +90,15 @@ Address::string_size () const
Address&
Address::operator= (const std::string &a_addr)
{
- m_addr = a_addr;
- str_utils::chomp (m_addr);
+ string addr = a_addr;
+ str_utils::chomp (addr);
+ if (!addr.empty ()
+ && !str_utils::string_is_number (addr)) {
+ stringstream msg;
+ msg << "Bad address format: " << addr;
+ THROW (msg.str ());
+ }
+ m_addr = addr;
return *this;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]