[glom/glom-1-16] Use unsigned integers where appropriate



commit 64f70c59435ac8cd1daace222c90932c4dad6adc
Author: David King <davidk openismus com>
Date:   Mon Oct 11 10:20:17 2010 +0200

    Use unsigned integers where appropriate
    
    * glom/libglom/connectionpool_backends/postgres.[cc|h]:
    * glom/libglom/connectionpool_backends/postgres_central.[cc|h]:
    * glom/libglom/connectionpool_backends/postgres_self.[cc|h]:
    * glom/libglom/data_structure/glomconversions.[cc|h]:
    * glom/libglom/document/document.[cc|h]: Use unsigned integers where
    the variable cannot be negative.

 ChangeLog                                          |   11 +++++++++++
 glom/libglom/connectionpool_backends/postgres.cc   |    4 ++--
 glom/libglom/connectionpool_backends/postgres.h    |    4 ++--
 .../connectionpool_backends/postgres_central.cc    |    4 ++--
 .../connectionpool_backends/postgres_central.h     |    4 ++--
 .../connectionpool_backends/postgres_self.cc       |    8 ++++----
 .../connectionpool_backends/postgres_self.h        |    4 ++--
 glom/libglom/data_structure/glomconversions.cc     |    4 ++--
 glom/libglom/data_structure/glomconversions.h      |    2 +-
 glom/libglom/document/document.cc                  |    4 ++--
 glom/libglom/document/document.h                   |    6 +++---
 11 files changed, 33 insertions(+), 22 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index ae6980d..15f6730 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-10-11  David King  <davidk openismus com>
+
+	Use unsigned integers where appropriate
+
+	* glom/libglom/connectionpool_backends/postgres.[cc|h]:
+	* glom/libglom/connectionpool_backends/postgres_central.[cc|h]:
+	* glom/libglom/connectionpool_backends/postgres_self.[cc|h]:
+	* glom/libglom/data_structure/glomconversions.[cc|h]:
+	* glom/libglom/document/document.[cc|h]: Use unsigned integers where
+	the variable cannot be negative.
+
 2010-10-08  David King  <davidk openismus com>
 
 	Remove some unnecessary includes
diff --git a/glom/libglom/connectionpool_backends/postgres.cc b/glom/libglom/connectionpool_backends/postgres.cc
index cf7106f..b0f644f 100644
--- a/glom/libglom/connectionpool_backends/postgres.cc
+++ b/glom/libglom/connectionpool_backends/postgres.cc
@@ -541,10 +541,10 @@ std::string Postgres::get_path_to_postgres_executable(const std::string& program
 }
 
 
-Glib::ustring Postgres::port_as_string(int port_num)
+Glib::ustring Postgres::port_as_string(unsigned int port_num)
 {
   Glib::ustring result;
-  char* cresult = g_strdup_printf("%d", port_num);
+  char* cresult = g_strdup_printf("%u", port_num);
   if(cresult)
     result = cresult;
   g_free(cresult);
diff --git a/glom/libglom/connectionpool_backends/postgres.h b/glom/libglom/connectionpool_backends/postgres.h
index 8cb4fec..d0881a7 100644
--- a/glom/libglom/connectionpool_backends/postgres.h
+++ b/glom/libglom/connectionpool_backends/postgres.h
@@ -111,10 +111,10 @@ protected:
   bool save_password_to_pgpass(const Glib::ustring username, const Glib::ustring& password, std::string& filepath_previous, std::string& filepath_original);
 
 protected:
-  static Glib::ustring port_as_string(int port_num);
+  static Glib::ustring port_as_string(unsigned int port_num);
 
   Glib::ustring m_host;
-  int m_port;
+  unsigned int m_port;
 
 private:
   float m_postgres_server_version;
diff --git a/glom/libglom/connectionpool_backends/postgres_central.cc b/glom/libglom/connectionpool_backends/postgres_central.cc
index 2666f78..b23293c 100644
--- a/glom/libglom/connectionpool_backends/postgres_central.cc
+++ b/glom/libglom/connectionpool_backends/postgres_central.cc
@@ -56,7 +56,7 @@ void PostgresCentralHosted::set_host(const Glib::ustring& value)
   }
 }
 
-void PostgresCentralHosted::set_port(int port)
+void PostgresCentralHosted::set_port(unsigned int port)
 {
   m_port = port;
 }
@@ -71,7 +71,7 @@ Glib::ustring PostgresCentralHosted::get_host() const
   return m_host;
 }
 
-int PostgresCentralHosted::get_port() const
+unsigned int PostgresCentralHosted::get_port() const
 {
   return m_port;
 }
diff --git a/glom/libglom/connectionpool_backends/postgres_central.h b/glom/libglom/connectionpool_backends/postgres_central.h
index 8d6044f..ead69f1 100644
--- a/glom/libglom/connectionpool_backends/postgres_central.h
+++ b/glom/libglom/connectionpool_backends/postgres_central.h
@@ -40,11 +40,11 @@ public:
    * Other ports will be tried if the specified port fails.
    */
   void set_host(const Glib::ustring& value);
-  void set_port(int port);
+  void set_port(unsigned int port);
   void set_try_other_ports(bool val);
 
   Glib::ustring get_host() const;
-  int get_port() const;
+  unsigned int get_port() const;
   bool get_try_other_ports() const;
 
 private:
diff --git a/glom/libglom/connectionpool_backends/postgres_self.cc b/glom/libglom/connectionpool_backends/postgres_self.cc
index dcafbae..e720e45 100644
--- a/glom/libglom/connectionpool_backends/postgres_self.cc
+++ b/glom/libglom/connectionpool_backends/postgres_self.cc
@@ -121,7 +121,7 @@ bool PostgresSelfHosted::get_self_hosting_active() const
   return m_port != 0;
 }
 
-int PostgresSelfHosted::get_port() const
+unsigned int PostgresSelfHosted::get_port() const
 {
   return m_port;
 }
@@ -424,7 +424,7 @@ Backend::StartupErrors PostgresSelfHosted::startup(const SlotProgress& slot_prog
   set_network_shared(slot_progress, m_network_shared); //Creates pg_hba.conf and pg_ident.conf
 
 
-  const int available_port = discover_first_free_port(PORT_POSTGRESQL_SELF_HOSTED_START, PORT_POSTGRESQL_SELF_HOSTED_END);
+  const unsigned int available_port = discover_first_free_port(PORT_POSTGRESQL_SELF_HOSTED_START, PORT_POSTGRESQL_SELF_HOSTED_END);
   //std::cout << "ConnectionPool::create_self_hosting():() : debug: Available port for self-hosting: " << available_port << std::endl;
   if(available_port == 0)
   {
@@ -626,7 +626,7 @@ bool PostgresSelfHosted::create_database(const Glib::ustring& database_name, con
   return attempt_create_database(database_name, m_host, port_as_string(m_port), username, password, error);
 }
 
-int PostgresSelfHosted::discover_first_free_port(int start_port, int end_port)
+unsigned int PostgresSelfHosted::discover_first_free_port(unsigned int start_port, unsigned int end_port)
 {
   //Open a socket so we can try to bind it to a port:
   const int fd = socket(AF_INET, SOCK_STREAM, 0);
@@ -646,7 +646,7 @@ int PostgresSelfHosted::discover_first_free_port(int start_port, int end_port)
   memset(&sa, 0, sizeof(sa));
   sa.sin_family = AF_INET;
 
-  int port_to_try = start_port;
+  guint16 port_to_try = start_port;
   while (port_to_try <= end_port)
   {
     sa.sin_port = htons(port_to_try);
diff --git a/glom/libglom/connectionpool_backends/postgres_self.h b/glom/libglom/connectionpool_backends/postgres_self.h
index 74aebf4..717f121 100644
--- a/glom/libglom/connectionpool_backends/postgres_self.h
+++ b/glom/libglom/connectionpool_backends/postgres_self.h
@@ -47,7 +47,7 @@ public:
    * @result The port number of the self-hosted server, or 0 if it is not
    * running.
    */
-  int get_port() const;
+  unsigned int get_port() const;
 
   /** Try to install postgres on the distro, though this will require a
    * distro-specific patch to the implementation.
@@ -69,7 +69,7 @@ private:
   /** Examine ports one by one, starting at @a starting_port, in increasing
    * order, and return the first one that is available.
    */
-  static int discover_first_free_port(int start_port, int end_port);
+  static unsigned int discover_first_free_port(unsigned int start_port, unsigned int end_port);
 
   /** Run the command-line with the --version option to discover what version
    * of PostgreSQL is installed, so we can use the appropriate configuration
diff --git a/glom/libglom/data_structure/glomconversions.cc b/glom/libglom/data_structure/glomconversions.cc
index ff4fe06..524149b 100644
--- a/glom/libglom/data_structure/glomconversions.cc
+++ b/glom/libglom/data_structure/glomconversions.cc
@@ -56,9 +56,9 @@ namespace Glom
 {
 
 
-int Conversions::get_stringstream_precision_default()
+unsigned int Conversions::get_stringstream_precision_default()
 {
-    static const int stringstream_precision_default = 15;
+    static const unsigned int stringstream_precision_default = 15;
     return stringstream_precision_default;
 }
 
diff --git a/glom/libglom/data_structure/glomconversions.h b/glom/libglom/data_structure/glomconversions.h
index dc79071..c4d0f51 100644
--- a/glom/libglom/data_structure/glomconversions.h
+++ b/glom/libglom/data_structure/glomconversions.h
@@ -32,7 +32,7 @@ namespace Glom
 
 namespace Conversions
 {
-  int get_stringstream_precision_default();
+  unsigned int get_stringstream_precision_default();
 
   ///Get text for display to the user.
   Glib::ustring get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value& value, const NumericFormat& numeric_format = NumericFormat());
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 8bb492d..9fcd696 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -377,7 +377,7 @@ Glib::ustring Document::get_connection_database() const
   return m_connection_database;
 }
 
-int Document::get_connection_port() const
+unsigned int Document::get_connection_port() const
 {
   return m_connection_port;
 }
@@ -424,7 +424,7 @@ void Document::set_connection_database(const Glib::ustring& strVal)
   }
 }
 
-void Document::set_connection_port(int port_number)
+void Document::set_connection_port(unsigned int port_number)
 {
   if(port_number != m_connection_port)
   {
diff --git a/glom/libglom/document/document.h b/glom/libglom/document/document.h
index 3d456b8..accd568 100644
--- a/glom/libglom/document/document.h
+++ b/glom/libglom/document/document.h
@@ -127,7 +127,7 @@ public:
 
   void set_connection_server(const Glib::ustring& strVal);
   void set_connection_database(const Glib::ustring& strVal);
-  void set_connection_port(int port_number);
+  void set_connection_port(unsigned int port_number);
   void set_connection_try_other_ports(bool val);
 
  /** Temporarily set a username in the document.
@@ -147,7 +147,7 @@ public:
 
   Glib::ustring get_connection_server() const;
   Glib::ustring get_connection_database() const;
-  int get_connection_port() const;
+  unsigned int get_connection_port() const;
   bool get_connection_try_other_ports() const;
 
   /** Retrieve a username previously set in the document.
@@ -514,7 +514,7 @@ private:
 
   Glib::ustring m_connection_server, m_connection_database;
   Glib::ustring m_connection_user; //Don't save the user.
-  int m_connection_port; //0 means any port. Ignored when self-hosting (which may use a different port each time).
+  unsigned int m_connection_port; //0 means any port. Ignored when self-hosting (which may use a different port each time).
   bool m_connection_try_other_ports; //Set to false for self-hosted or browsed-from-network documents.
 
   class LayoutInfo



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]