From: Christian Grothoff Date: Fri, 11 Jun 2010 21:57:37 +0000 (+0000) Subject: use constants instead of casting -1 X-Git-Tag: initial-import-from-subversion-38251~21412 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=719fb963b47d487112879ff2cb9d10cff88b84f5;p=oweals%2Fgnunet.git use constants instead of casting -1 --- diff --git a/src/core/gnunet-service-core.c b/src/core/gnunet-service-core.c index 2d06bd440..97ed57360 100644 --- a/src/core/gnunet-service-core.c +++ b/src/core/gnunet-service-core.c @@ -1029,7 +1029,7 @@ handle_client_request_info (void *cls, if (old_preference > n->current_preference) { /* overflow; cap at maximum value */ - n->current_preference = (unsigned long long) -1; + n->current_preference = ULLONG_MAX; } update_preference_sum (n->current_preference - old_preference); #if DEBUG_CORE_QUOTA @@ -1545,7 +1545,7 @@ select_messages (struct Neighbour *n, while (GNUNET_YES == discard_low_prio) { min = NULL; - min_prio = -1; + min_prio = UINT_MAX; discard_low_prio = GNUNET_NO; /* calculate number of bytes available for transmission at time "t" */ avail = GNUNET_BANDWIDTH_tracker_get_available (&n->available_send_window); @@ -2014,7 +2014,7 @@ process_plaintext_neighbour_queue (struct Neighbour *n) (unsigned int) ntohl (n->bw_in.value__), GNUNET_i2s (&n->peer)); #endif - ph->iv_seed = htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, -1)); + ph->iv_seed = htonl (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, UINT32_MAX)); ph->sequence_number = htonl (++n->last_sequence_number_sent); ph->inbound_bw_limit = n->bw_in; ph->timestamp = GNUNET_TIME_absolute_hton (GNUNET_TIME_absolute_get ()); @@ -2122,10 +2122,10 @@ create_neighbour (const struct GNUNET_PeerIdentity *pid) n->set_key_retry_frequency = INITIAL_SET_KEY_RETRY_FREQUENCY; n->bw_in = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; n->bw_out = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; - n->bw_out_internal_limit = GNUNET_BANDWIDTH_value_init ((uint32_t) - 1); + n->bw_out_internal_limit = GNUNET_BANDWIDTH_value_init (UINT32_MAX); n->bw_out_external_limit = GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT; n->ping_challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - (uint32_t) - 1); + UINT32_MAX); neighbour_quota_update (n, NULL); consider_free_neighbour (n); return n; @@ -2186,7 +2186,7 @@ handle_client_send (void *cls, #endif /* bound queue size */ discard_expired_messages (n); - min_prio = (unsigned int) -1; + min_prio = UINT32_MAX; min_prio_entry = NULL; min_prio_prev = NULL; queue_size = 0; @@ -3641,8 +3641,8 @@ neighbour_quota_update (void *cls, if (bandwidth_target_out_bps > need_per_second) distributable = bandwidth_target_out_bps - need_per_second; share = distributable * pref_rel; - if (share + need_per_peer > ( (uint32_t)-1)) - q_in = GNUNET_BANDWIDTH_value_init ((uint32_t) -1); + if (share + need_per_peer > UINT32_MAX) + q_in = GNUNET_BANDWIDTH_value_init (UINT32_MAX); else q_in = GNUNET_BANDWIDTH_value_init (need_per_peer + (uint32_t) share); /* check if we want to disconnect for good due to inactivity */ diff --git a/src/datastore/datastore.h b/src/datastore/datastore.h index aa2646c0a..f827f8766 100644 --- a/src/datastore/datastore.h +++ b/src/datastore/datastore.h @@ -27,7 +27,7 @@ #ifndef DATASTORE_H #define DATASTORE_H -#define DEBUG_DATASTORE GNUNET_NO +#define DEBUG_DATASTORE GNUNET_YES #include "gnunet_util_lib.h" diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c index ff3eb09e1..807ade93c 100644 --- a/src/fs/fs_download.c +++ b/src/fs/fs_download.c @@ -1647,7 +1647,8 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h, struct GNUNET_FS_ProgressInfo pi; struct GNUNET_FS_DownloadContext *dc; - if (sr->download != NULL) + if ( (sr != NULL) && + (sr->download != NULL) ) { GNUNET_break (0); return NULL; diff --git a/src/fs/gnunet-service-fs.c b/src/fs/gnunet-service-fs.c index c5a47973c..d7dc86002 100644 --- a/src/fs/gnunet-service-fs.c +++ b/src/fs/gnunet-service-fs.c @@ -2150,7 +2150,7 @@ forward_request_task (void *cls, pr->irc = GNUNET_CORE_peer_change_preference (sched, cfg, &psc.target, GNUNET_CONSTANTS_SERVICE_TIMEOUT, - GNUNET_BANDWIDTH_value_init ((uint32_t) -1 /* no limit */), + GNUNET_BANDWIDTH_value_init (UINT32_MAX), DBLOCK_SIZE * 2, (uint64_t) cp->inc_preference, &target_reservation_cb, @@ -2348,7 +2348,8 @@ process_reply (void *cls, if (pr->cp != NULL) { GNUNET_PEER_change_rc (prq->sender->last_p2p_replies - [prq->sender->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE], -1); + [prq->sender->last_p2p_replies_woff % P2P_SUCCESS_LIST_SIZE], + -1); GNUNET_PEER_change_rc (pr->cp->pid, 1); prq->sender->last_p2p_replies [(prq->sender->last_p2p_replies_woff++) % P2P_SUCCESS_LIST_SIZE] @@ -2515,7 +2516,7 @@ process_reply (void *cls, reply->cont = &transmit_reply_continuation; reply->cont_cls = pr; reply->msize = msize; - reply->priority = (uint32_t) -1; /* send replies first! */ + reply->priority = UINT32_MAX; /* send replies first! */ pm = (struct PutMessage*) &reply[1]; pm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_PUT); pm->header.size = htons (msize); diff --git a/src/fs/test_gnunet_service_fs_migration.c b/src/fs/test_gnunet_service_fs_migration.c index 9cf8c3773..835650ef6 100644 --- a/src/fs/test_gnunet_service_fs_migration.c +++ b/src/fs/test_gnunet_service_fs_migration.c @@ -244,6 +244,7 @@ main (int argc, char *argv[]) "WARNING", #endif NULL); + system ("netstat -ntpl"); GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx, "test-gnunet-service-fs-migration", "nohelp", options, &run, NULL); diff --git a/src/fs/test_gnunet_service_fs_migration_data.conf b/src/fs/test_gnunet_service_fs_migration_data.conf index 82606092c..9a388e0e8 100644 --- a/src/fs/test_gnunet_service_fs_migration_data.conf +++ b/src/fs/test_gnunet_service_fs_migration_data.conf @@ -12,12 +12,13 @@ HOSTNAME = localhost [transport] PORT = 43465 PLUGINS = tcp -#DEBUG = YES +DEBUG = YES [arm] PORT = 43466 HOSTNAME = localhost DEFAULTSERVICES = fs +OPTIONS = -L DEBUG [datastore] #DEBUG = YES diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index 7afbbd48b..4f369812d 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c @@ -726,7 +726,7 @@ create_scale_free (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connectio { probability = pg->peers[i].num_connections / (double)previous_total_connections; random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, - (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL); + UINT64_MAX)) / ( (double) UINT64_MAX); #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Considering connecting peer %d to peer %d\n", @@ -820,7 +820,7 @@ create_small_world_ring(struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Conn for (j = 0; j < connsPerPeer / 2; j++) { random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, - (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL); + UINT64_MAX) / ( (double) UINT64_MAX)); if (random < percentage) { /* Connect to uniformly selected random peer */ @@ -1035,7 +1035,7 @@ create_small_world (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti probability = 1.0 / (distance * distance); /* Choose a random value between 0 and 1 */ random = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, - (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL); + UINT64_MAX)) / ( (double) UINT64_MAX); /* If random < probability, then connect the two nodes */ if (random < probability) smallWorldConnections += proc (pg, j, k); @@ -1086,7 +1086,7 @@ create_erdos_renyi (struct GNUNET_TESTING_PeerGroup *pg, GNUNET_TESTING_Connecti inner_count++) { temp_rand = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, - (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL); + UINT64_MAX)) / ( (double) UINT64_MAX); #if VERBOSE_TESTING GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("rand is %f probability is %f\n"), temp_rand, @@ -2077,7 +2077,7 @@ random_connect_iterator (void *cls, uint32_t second_pos; GNUNET_HashCode first_hash; random_number = ((double) GNUNET_CRYPTO_random_u64(GNUNET_CRYPTO_QUALITY_WEAK, - (uint64_t)-1LL)) / ( (double) (uint64_t) -1LL); + UINT64_MAX)) / ( (double) UINT64_MAX); if (random_number < random_ctx->percentage) { GNUNET_assert(GNUNET_OK == GNUNET_CONTAINER_multihashmap_put(random_ctx->first->connect_peers_working_set, key, value, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 1dcd988a9..fd47130a1 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -3132,7 +3132,7 @@ send_periodic_ping (void *cls, va = GNUNET_malloc (sizeof (struct ValidationEntry) + peer_address->addrlen); va->transport_name = GNUNET_strdup (tp->short_name); va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - (unsigned int) -1); + UINT_MAX); va->send_time = GNUNET_TIME_absolute_get(); va->session = peer_address->session; if (peer_address->addr != NULL) @@ -3690,7 +3690,7 @@ run_validation (void *cls, chvc->ve_count++; va->transport_name = GNUNET_strdup (tname); va->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, - (unsigned int) -1); + UINT_MAX); va->send_time = GNUNET_TIME_absolute_get(); va->addr = (const void*) &va[1]; memcpy (&va[1], addr, addrlen); diff --git a/src/util/time.c b/src/util/time.c index 3d53e0af2..6a5a314da 100644 --- a/src/util/time.c +++ b/src/util/time.c @@ -84,7 +84,7 @@ GNUNET_TIME_relative_get_unit () struct GNUNET_TIME_Relative GNUNET_TIME_relative_get_forever () { - static struct GNUNET_TIME_Relative forever = { (uint64_t) - 1LL }; + static struct GNUNET_TIME_Relative forever = { UINT64_MAX }; return forever; } @@ -94,7 +94,7 @@ GNUNET_TIME_relative_get_forever () struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get_forever () { - static struct GNUNET_TIME_Absolute forever = { (uint64_t) - 1LL }; + static struct GNUNET_TIME_Absolute forever = { UINT64_MAX }; return forever; } @@ -108,7 +108,7 @@ struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute (struct GNUNET_TIME_Relative rel) { struct GNUNET_TIME_Absolute ret; - if (rel.value == (uint64_t) - 1LL) + if (rel.value == UINT64_MAX) return GNUNET_TIME_absolute_get_forever (); struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); if (rel.value + now.value < rel.value) @@ -196,7 +196,7 @@ struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining (struct GNUNET_TIME_Absolute future) { struct GNUNET_TIME_Relative ret; - if (future.value == (uint64_t) - 1LL) + if (future.value == UINT64_MAX) return GNUNET_TIME_relative_get_forever (); struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); if (now.value > future.value) @@ -217,7 +217,7 @@ GNUNET_TIME_absolute_get_difference (struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Absolute end) { struct GNUNET_TIME_Relative ret; - if (end.value == (uint64_t) - 1LL) + if (end.value == UINT64_MAX) return GNUNET_TIME_relative_get_forever (); if (end.value < start.value) return GNUNET_TIME_relative_get_zero (); @@ -238,7 +238,7 @@ GNUNET_TIME_absolute_get_duration (struct GNUNET_TIME_Absolute hence) struct GNUNET_TIME_Relative ret; now = GNUNET_TIME_absolute_get (); - GNUNET_assert (hence.value != (uint64_t) - 1LL); + GNUNET_assert (hence.value != UINT64_MAX); if (hence.value > now.value) return GNUNET_TIME_relative_get_zero (); ret.value = now.value - hence.value; @@ -258,8 +258,8 @@ GNUNET_TIME_absolute_add (struct GNUNET_TIME_Absolute start, { struct GNUNET_TIME_Absolute ret; - if ((start.value == (uint64_t) - 1LL) || - (duration.value == (uint64_t) - 1LL)) + if ((start.value == UINT64_MAX) || + (duration.value == UINT64_MAX)) return GNUNET_TIME_absolute_get_forever (); if (start.value + duration.value < start.value) { @@ -382,7 +382,7 @@ GNUNET_TIME_relative_add (struct GNUNET_TIME_Relative a1, { struct GNUNET_TIME_Relative ret; - if ((a1.value == (uint64_t) - 1LL) || (a2.value == (uint64_t) - 1LL)) + if ((a1.value == UINT64_MAX) || (a2.value == UINT64_MAX)) return GNUNET_TIME_relative_get_forever (); if (a1.value + a2.value < a1.value) { @@ -409,7 +409,7 @@ GNUNET_TIME_relative_subtract (struct GNUNET_TIME_Relative a1, if (a2.value >= a1.value) return GNUNET_TIME_relative_get_zero (); - if (a1.value == (uint64_t) - 1LL) + if (a1.value == UINT64_MAX) return GNUNET_TIME_relative_get_forever (); ret.value = a1.value - a2.value; return ret;