libpreludedb/master: Fixes some warnings uncovered by -Wextra

[email protected] Fri, 29 Jan 2010 18:00:43 +0100 (CET)
Newsgroups gmane.comp.security.ids.prelude.cvs
Message-ID <[email protected]>
commit b7d60fbb66c09f0a188b5ce6387ed53c5efdcce7
Author: Yoann Vandoorselaere <[email protected]>
Date:   Thu Jan 21 09:39:57 2010 +0100

    Fixes some warnings uncovered by -Wextra


========================================

 plugins/format/classic/classic-delete.c       |    5 ++---
 plugins/format/classic/classic-get.c          |    2 +-
 plugins/format/classic/classic-path-resolve.c |    2 +-
 plugins/format/classic/classic-sql-select.c   |    2 +-
 plugins/sql/mysql/mysql.c                     |    4 ++--
 plugins/sql/pgsql/pgsql.c                     |    8 +++++---
 plugins/sql/sqlite3/sqlite3.c                 |    5 +++--
 preludedb-admin.c                             |    2 +-
 src/preludedb-error.c                         |    2 +-
 src/preludedb-path-selection.c                |    4 ++--
 src/preludedb-plugin-sql.c                    |    2 +-
 src/preludedb-sql.c                           |    4 ++--
 src/preludedb.c                               |    2 +-
 13 files changed, 23 insertions(+), 21 deletions(-)

========================================

diff --git a/plugins/format/classic/classic-delete.c b/plugins/format/classic/classic-delete.c
index 646f3db..c17b0bf 100644
--- a/plugins/format/classic/classic-delete.c
+++ b/plugins/format/classic/classic-delete.c
@@ -41,9 +41,8 @@
 
 static int delete_message(preludedb_sql_t *sql, unsigned int count, const char **queries, const char *idents)
 {
-        int i;
-        int ret;
-        int tmp;
+        unsigned int i;
+        int ret, tmp;
 
         ret = preludedb_sql_transaction_start(sql);
         if ( ret < 0 )
diff --git a/plugins/format/classic/classic-get.c b/plugins/format/classic/classic-get.c
index b71de37..3760586 100644
--- a/plugins/format/classic/classic-get.c
+++ b/plugins/format/classic/classic-get.c
@@ -1141,7 +1141,7 @@ static int get_file_access(preludedb_sql_t *sql,
         preludedb_sql_field_t *field;
         idmef_file_access_t *file_access;
         uint32_t file_access_count;
-        int cnt;
+        unsigned int cnt;
         int ret;
 
         ret = preludedb_sql_query_sprintf(sql, &table,
diff --git a/plugins/format/classic/classic-path-resolve.c b/plugins/format/classic/classic-path-resolve.c
index a947541..4de7e06 100644
--- a/plugins/format/classic/classic-path-resolve.c
+++ b/plugins/format/classic/classic-path-resolve.c
@@ -272,7 +272,7 @@ static const classic_idmef_class_t default_class = {
 static const classic_idmef_class_t *search_path(const idmef_path_t *path)
 {
         idmef_class_id_t class_id;
-        int i;
+        unsigned int i;
 
         class_id = idmef_path_get_class(path, idmef_path_get_depth(path) - 2);
 
diff --git a/plugins/format/classic/classic-sql-select.c b/plugins/format/classic/classic-sql-select.c
index 56ae899..9737fcd 100644
--- a/plugins/format/classic/classic-sql-select.c
+++ b/plugins/format/classic/classic-sql-select.c
@@ -103,7 +103,7 @@ int classic_sql_select_add_field(classic_sql_select_t *select, const char *field
                 { PRELUDEDB_SELECTED_OBJECT_FUNCTION_STD, "STD" },
                 { PRELUDEDB_SELECTED_OBJECT_FUNCTION_COUNT, "COUNT" }
         };
-        int i;
+        unsigned int i;
         const char *function_name = NULL;
         int ret;
 
diff --git a/plugins/sql/mysql/mysql.c b/plugins/sql/mysql/mysql.c
index b807426..cbe476b 100644
--- a/plugins/sql/mysql/mysql.c
+++ b/plugins/sql/mysql/mysql.c
@@ -370,7 +370,7 @@ static int sql_build_time_constraint_string(prelude_string_t *output, const char
         int ret;
 
         ret = snprintf(buf, sizeof(buf), "DATE_ADD(%s, INTERVAL %d HOUR)", field, gmt_offset / 3600);
-        if ( ret < 0 || ret >= sizeof(buf) )
+        if ( ret < 0 || (size_t) ret >= sizeof(buf) )
                 return preludedb_error(PRELUDEDB_ERROR_GENERIC);
 
         sql_operator = get_operator_string(operator);
@@ -455,7 +455,7 @@ static int sql_build_time_interval_string(preludedb_sql_time_constraint_type_t t
 
         ret = snprintf(buf, size, "INTERVAL %d %s", value, type_str);
 
-        return (ret < 0 || ret >= size) ? preludedb_error(PRELUDEDB_ERROR_GENERIC) : 0;
+        return (ret < 0 || (size_t) ret >= size) ? preludedb_error(PRELUDEDB_ERROR_GENERIC) : 0;
 }
 
 
diff --git a/plugins/sql/pgsql/pgsql.c b/plugins/sql/pgsql/pgsql.c
index 43a7e7a..cb54242 100644
--- a/plugins/sql/pgsql/pgsql.c
+++ b/plugins/sql/pgsql/pgsql.c
@@ -302,9 +302,11 @@ static int sql_fetch_row(void *s, void *resource, void **row)
 static int sql_fetch_field(void *session, void *resource, void *r,
                            unsigned int column_num, const char **value, size_t *len)
 {
+        int nfields;
         struct pg_result *res = resource;
 
-        if ( column_num >= PQnfields(res->result) )
+        nfields = PQnfields(res->result);
+        if ( nfields < 0 || column_num >= (unsigned int) nfields )
                 return preludedb_error(PRELUDEDB_ERROR_INVALID_COLUMN_NUM);
 
         if ( PQgetisnull(res->result, res->row, column_num) )
@@ -391,7 +393,7 @@ static int sql_build_time_constraint_string(prelude_string_t *output, const char
         int ret;
 
         ret = snprintf(buf, sizeof (buf), "%s + INTERVAL '%d HOUR'", field, gmt_offset / 3600);
-        if ( ret < 0 || ret >= sizeof (buf) )
+        if ( ret < 0 || (size_t) ret >= sizeof (buf) )
                 return preludedb_error(PRELUDEDB_ERROR_GENERIC);
 
         sql_operator = get_operator_string(operator);
@@ -476,7 +478,7 @@ static int sql_build_time_interval_string(preludedb_sql_time_constraint_type_t t
 
         ret = snprintf(buf, size, "INTERVAL '%d %s'", value, type_str);
 
-        return (ret < 0 || ret >= size) ? preludedb_error(PRELUDEDB_ERROR_GENERIC) : 0;
+        return (ret < 0 || (size_t) ret >= size) ? preludedb_error(PRELUDEDB_ERROR_GENERIC) : 0;
 }
 
 
diff --git a/plugins/sql/sqlite3/sqlite3.c b/plugins/sql/sqlite3/sqlite3.c
index 1a16522..daa3857 100644
--- a/plugins/sql/sqlite3/sqlite3.c
+++ b/plugins/sql/sqlite3/sqlite3.c
@@ -365,7 +365,8 @@ static const char *sql_get_column_name(void *session, void *resource, unsigned i
 
 static int sql_get_column_num(void *session, void *resource, const char *column_name)
 {
-        int ret, i;
+        int ret;
+        unsigned int i;
         sqlite3_resource_t *res = resource;
 
         for ( i = 0; i < res->ncolumn; i++ ) {
@@ -503,7 +504,7 @@ static int sql_build_time_constraint_string(prelude_string_t *output, const char
         int ret;
 
         ret = snprintf(buf, sizeof(buf), "DATETIME(%s, '%d hours')", field, gmt_offset / 3600);
-        if ( ret < 0 || ret >= sizeof(buf) )
+        if ( ret < 0 || (size_t) ret >= sizeof(buf) )
                 return preludedb_error(PRELUDEDB_ERROR_GENERIC);
 
         sql_operator = get_operator_string(operator);
diff --git a/preludedb-admin.c b/preludedb-admin.c
index 3ec5e3f..dda7885 100644
--- a/preludedb-admin.c
+++ b/preludedb-admin.c
@@ -894,7 +894,7 @@ static int do_read_message(prelude_io_t *io, prelude_msg_t **msg, idmef_message_
                 return 1;
         }
 
-        if ( limit != -1 && cur_count >= limit ) {
+        if ( limit != -1 && cur_count >= (uint64_t) limit ) {
                 prelude_msg_destroy(*msg);
                 return 0;
         }
diff --git a/src/preludedb-error.c b/src/preludedb-error.c
index ae771ac..ffb27af 100644
--- a/src/preludedb-error.c
+++ b/src/preludedb-error.c
@@ -60,7 +60,7 @@ const char *preludedb_strerror(preludedb_error_t error)
                 preludedb_error_code_t code;
 
                 code = prelude_error_get_code(error);
-                if ( code < 0 || code >= sizeof(error_strings) / sizeof(*error_strings) )
+                if ( code >= sizeof(error_strings) / sizeof(*error_strings) )
                         return NULL;
 
                 return error_strings[code];
diff --git a/src/preludedb-path-selection.c b/src/preludedb-path-selection.c
index ee0112c..e3fa72c 100644
--- a/src/preludedb-path-selection.c
+++ b/src/preludedb-path-selection.c
@@ -64,7 +64,7 @@ int preludedb_selected_path_new(preludedb_selected_path_t **selected_path,
 
 static int parse_filter(const char *str, size_t len)
 {
-        int i;
+        unsigned int i;
         struct {
                 const char *name;
                 int flag;
@@ -110,7 +110,7 @@ static int parse_filters(const char *str)
 
 static int parse_function(const char *str)
 {
-        int i;
+        unsigned int i;
         struct {
                 const char *name;
                 size_t len;
diff --git a/src/preludedb-plugin-sql.c b/src/preludedb-plugin-sql.c
index 9aaed92..316ceee 100644
--- a/src/preludedb-plugin-sql.c
+++ b/src/preludedb-plugin-sql.c
@@ -379,7 +379,7 @@ int _preludedb_plugin_sql_build_timestamp_string(preludedb_plugin_sql_t *plugin,
                        lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
                        lt->tm_hour, lt->tm_min, lt->tm_sec);
 
-        return (ret < 0 || ret >= size) ? -1 : 0;
+        return (ret < 0 || (size_t) ret >= size) ? -1 : 0;
 }
 
 
diff --git a/src/preludedb-sql.c b/src/preludedb-sql.c
index b779d09..d90efe1 100644
--- a/src/preludedb-sql.c
+++ b/src/preludedb-sql.c
@@ -1182,8 +1182,8 @@ static int build_criterion_fixed_value(preludedb_sql_t *sql,
 static int build_criterion_broken_down_time_equal(preludedb_sql_t *sql, prelude_string_t *output,
                                                   const char *field, idmef_criterion_operator_t op, const struct tm *lt)
 {
-        int ret;
-        int i, prev = 0, year, month;
+        unsigned int i;
+        int ret, prev = 0, year, month;
         const struct {
                 preludedb_sql_time_constraint_type_t type;
                 const int *field_ptr;
diff --git a/src/preludedb.c b/src/preludedb.c
index 161e6ed..2d99fa8 100644
--- a/src/preludedb.c
+++ b/src/preludedb.c
@@ -324,7 +324,7 @@ char *preludedb_get_error(preludedb_t *db, preludedb_error_t error, char *errbuf
         tmp = preludedb_error(prelude_error_get_code(error));
 
         ret = snprintf(errbuf, size, "%s: %s", preludedb_strerror(tmp), preludedb_strerror(error));
-        if ( ret < 0 || ret >= size )
+        if ( ret < 0 || (size_t) ret >= size )
                 return NULL;
 
         return errbuf;
_______________________________________________
Prelude-cvslog site list
[email protected]
http://lists.prelude-ids.org/mailman/listinfo/prelude-cvslog