A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
please sonar: dont apply binary operators to signed ints
[simgrid.git]
/
examples
/
msg
/
dht-kademlia
/
node.c
diff --git
a/examples/msg/dht-kademlia/node.c
b/examples/msg/dht-kademlia/node.c
index
08aa37c
..
e854b52
100644
(file)
--- a/
examples/msg/dht-kademlia/node.c
+++ b/
examples/msg/dht-kademlia/node.c
@@
-20,7
+20,7
@@
node_t node_init(unsigned int node_id)
node->id = node_id;
node->table = routing_table_init(node_id);
node->id = node_id;
node->table = routing_table_init(node_id);
- s
printf(node->mailbox, "%0*x", MAILBOX_NAME_SIZE
, node_id);
+ s
nprintf(node->mailbox,MAILBOX_NAME_SIZE-1, "%d"
, node_id);
node->find_node_failed = 0;
node->find_node_success = 0;
node->find_node_failed = 0;
node->find_node_success = 0;
@@
-115,9
+115,9
@@
unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix)
{
if (prefix == 0) {
return 0;
{
if (prefix == 0) {
return 0;
+ } else {
+ return (1 << ((unsigned int)(prefix - 1))) ^ id;
}
}
- unsigned int n = 1 << (prefix - 1);
- return n ^ id;
}
/** @brief Returns the prefix of an identifier.
}
/** @brief Returns the prefix of an identifier.
@@
-127,8
+127,8
@@
unsigned int get_id_in_prefix(unsigned int id, unsigned int prefix)
*/
unsigned int get_node_prefix(unsigned int id, unsigned int nb_bits)
{
*/
unsigned int get_node_prefix(unsigned int id, unsigned int nb_bits)
{
- unsigned int
j,
size = sizeof(unsigned int) * 8;
- for (j = 0; j < size; j++) {
+ unsigned int size = sizeof(unsigned int) * 8;
+ for (
unsigned int
j = 0; j < size; j++) {
if (((id >> (size - 1 - j)) & 0x1) != 0) {
return nb_bits - (j);
}
if (((id >> (size - 1 - j)) & 0x1) != 0) {
return nb_bits - (j);
}
@@
-136,11
+136,10
@@
unsigned int get_node_prefix(unsigned int id, unsigned int nb_bits)
return 0;
}
return 0;
}
-/** @brief Gets the mailbox name of a host given its identifier
- */
+/** @brief Gets the mailbox name of a host given its identifier */
void get_node_mailbox(unsigned int id, char *mailbox)
{
void get_node_mailbox(unsigned int id, char *mailbox)
{
- s
printf(mailbox, "%0*x", MAILBOX_NAME_SIZE
, id);
+ s
nprintf(mailbox,MAILBOX_NAME_SIZE-1, "%d"
, id);
}
/** Constructor, build a new contact information. */
}
/** Constructor, build a new contact information. */