]> git.proxmox.com Git - libgit2.git/commitdiff
msvc: Fix some compiler warnings
authorRamsay Jones <ramsay@ramsay1.demon.co.uk>
Tue, 1 Jun 2010 18:29:15 +0000 (19:29 +0100)
committerAndreas Ericsson <ae@op5.se>
Wed, 2 Jun 2010 09:18:55 +0000 (11:18 +0200)
In particular, the compiler issues the following warnings:

    src/revobject.c(29) : warning C4305: 'initializing' : truncation \
        from 'double' to 'const float'
    src/revobject.c(56) : warning C4244: '=' : conversion from \
        'const float' to 'unsigned int', possible loss of data
    src/revobject.c(149) : warning C4244: '=' : conversion from \
        'const float' to 'unsigned int', possible loss of data

In order to suppress the warnings we change the type of max_load_factor
to double, rather than change the initialiser to 0.65f, and cast the
result type of the expressions to 'unsigned int' as expected by the
assignment operators. Note that double should be able to represent all
unsigned int values without loss.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Signed-off-by: Andreas Ericsson <ae@op5.se>
src/revobject.c

index ce4be0c1c06f8e311b68f70c89165cff698d5c85..4c64f551d91b63e8b58d08d9d0674e1fd59b2afd 100644 (file)
@@ -26,7 +26,7 @@
 #include "common.h"
 #include "revobject.h"
 
-const float max_load_factor = 0.65;
+const double max_load_factor = 0.65;
 
 unsigned int git_revpool_table__hash(const git_oid *id)
 {
@@ -53,7 +53,7 @@ git_revpool_table *git_revpool_table_create(unsigned int min_size)
 
        table->size_mask = min_size;
        table->count = 0;
-       table->max_count = (min_size + 1) * max_load_factor;
+       table->max_count = (unsigned int)((min_size + 1) * max_load_factor);
 
        table->nodes = git__malloc((min_size + 1) * sizeof(git_revpool_node *));
 
@@ -146,7 +146,7 @@ void git_revpool_table_resize(git_revpool_table *table)
        free(table->nodes);
        table->nodes = new_nodes;
        table->size_mask = (new_size - 1);
-       table->max_count = new_size * max_load_factor;
+       table->max_count = (unsigned int)(new_size * max_load_factor);
 }