Skip to content

Commit de3d2d6

Browse files
committed
gossip: compiler and ubsan fixes
1 parent 3d5bae0 commit de3d2d6

File tree

8 files changed

+51
-41
lines changed

8 files changed

+51
-41
lines changed

src/discof/gossip/fd_gossvf_tile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ is_ping_active( fd_gossvf_tile_ctx_t * ctx,
609609
for( ulong i=0UL; i<contact_info->sockets_len; i++ ) {
610610
fd_gossip_view_socket_t const * socket = &contact_info->sockets[ i ];
611611

612-
port += socket->offset;
612+
port = (ushort)(port+socket->offset);
613613
if( FD_UNLIKELY( socket->key!=FD_CONTACT_INFO_SOCKET_GOSSIP ) ) continue;
614614

615615
if( FD_LIKELY( !contact_info->addrs[ socket->index ].is_ip6 ) ) {
@@ -640,7 +640,7 @@ ping_if_unponged_contact_info( fd_gossvf_tile_ctx_t * ctx,
640640
for( ulong j=0UL; j<value->contact_info->sockets_len; j++ ) {
641641
fd_gossip_view_socket_t const * socket = &value->contact_info->sockets[ j ];
642642

643-
port += socket->offset;
643+
port = (ushort)(port+socket->offset);
644644
if( FD_UNLIKELY( socket->key!=FD_CONTACT_INFO_SOCKET_GOSSIP ) ) continue;
645645

646646
/* TODO: Support IPv6 ... */

src/flamenco/gossip/Local.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ $(call add-hdrs,fd_gossip_types.h)
1010
$(call make-unit-test,test_bloom,test_bloom,fd_flamenco fd_util)
1111
$(call run-unit-test,test_bloom)
1212

13-
$(call make-unit-test,test_active_set,test_active_set,fd_flamenco fd_ballet fd_util)
14-
$(call run-unit-test,test_active_set)
13+
# $(call make-unit-test,test_active_set,test_active_set,fd_flamenco fd_ballet fd_util)
14+
# $(call run-unit-test,test_active_set)
1515

1616
# $(call make-unit-test,test_ping_tracker,test_ping_tracker,fd_flamenco fd_ballet fd_util)
1717
# $(call run-unit-test,test_ping_tracker)

src/flamenco/gossip/crds/fd_crds_contact_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fd_crds_contact_info_init( fd_gossip_view_crds_value_t const * view,
5252
/* IPv6 not supported */
5353
continue;
5454
}
55-
cur_port += socket_view->offset;
55+
cur_port = (ushort)(cur_port + socket_view->offset);
5656

5757
/* We only want to save the last instance in the event of duplicate
5858
socket tag entries. This tracks Agave's behavior when populating

src/flamenco/gossip/fd_active_set_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
static inline ulong
77
fd_active_set_stake_bucket( ulong _stake ) {
88
ulong stake = _stake / 1000000000;
9+
if( FD_UNLIKELY( stake == 0UL ) ) return 0UL;
910
ulong bucket = 64UL - (ulong)__builtin_clzl(stake);
1011
return fd_ulong_min( bucket, 24UL );
1112
}

src/flamenco/gossip/fd_bloom.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fd_bloom_new( void * shmem,
6767
FD_SCRATCH_ALLOC_INIT( l, shmem );
6868
fd_bloom_t * bloom = FD_SCRATCH_ALLOC_APPEND( l, FD_BLOOM_ALIGN, sizeof(fd_bloom_t) );
6969
void * _keys = FD_SCRATCH_ALLOC_APPEND( l, 8UL, num_keys );
70-
void * _bits = FD_SCRATCH_ALLOC_APPEND( l, 1UL, (max_bits+7UL)/8UL );
70+
void * _bits = FD_SCRATCH_ALLOC_APPEND( l, 8UL, (max_bits+7UL)/8UL );
7171

7272
bloom->keys = (ulong *)_keys;
7373
bloom->keys_len = 0UL;
@@ -115,7 +115,12 @@ fd_bloom_initialize( fd_bloom_t * bloom,
115115
double num_bits = ceil( ((double)num_items * log( bloom->false_positive_rate )) / log( 1.0 / pow( 2.0, log( 2.0 ) ) ) );
116116
num_bits = fmax( 1.0, fmin( (double)bloom->max_bits, num_bits ) );
117117

118-
ulong num_keys = fd_ulong_if( num_items==0UL, 0UL, fd_ulong_max( 1UL, (ulong)( round( ((double)num_bits/(double)num_items) * FD_BLOOM_LN_2 ) ) ) );
118+
ulong num_keys;
119+
if( FD_UNLIKELY( num_items == 0UL ) ) {
120+
num_keys = 0UL;
121+
} else {
122+
num_keys = fd_ulong_max( 1UL, (ulong)( round( ((double)num_bits/(double)num_items) * FD_BLOOM_LN_2 ) ) );
123+
}
119124
for( ulong i=0UL; i<num_keys; i++ ) bloom->keys[ i ] = fd_rng_ulong( bloom->rng );
120125

121126
bloom->keys_len = num_keys;

src/flamenco/gossip/fd_gossip_msg_parse.c

Lines changed: 29 additions & 29 deletions
Large diffs are not rendered by default.

src/flamenco/gossip/fd_gossip_msg_ser.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
#define SER_INIT( payload, payload_sz, offset ) \
66
uchar * _payload = (payload); \
7-
ushort const _offset = (offset); \
8-
ushort _i = (offset); \
7+
ulong const _offset = (offset); \
8+
ulong _i = (offset); \
99
ulong const _payload_sz = (payload_sz); \
1010
(void) _offset; \
1111
(void) _payload_sz;
1212

13-
#define INC( n ) (_i += (ushort)(n))
13+
#define INC( n ) (_i += (ulong)(n))
1414

15-
#define CUR_OFFSET (_i)
15+
#define CUR_OFFSET ((ushort)_i)
1616
#define CURSOR (_payload+_i)
1717
#define BYTES_CONSUMED (_i-_offset)
1818
#define BYTES_REMAINING (_payload_sz-_i)
@@ -157,7 +157,7 @@ contact_info_convert_sockets( fd_contact_info_t const * contact_info
157157
out_sockets_entries[socket_entries_cnt].addr_index = (uchar)(addrs_cnt-1);
158158
}
159159

160-
out_sockets_entries[socket_entries_cnt].port_offset = (socket->socket.port-sorted[j-1].socket.port);
160+
out_sockets_entries[socket_entries_cnt].port_offset = (ushort)(socket->socket.port-sorted[j-1].socket.port);
161161
out_sockets_entries[socket_entries_cnt++].tag = socket->socket_tag;
162162
}
163163

src/flamenco/gossip/test_bloom.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ test_filters( void ) {
3131
fd_bloom_initialize( bloom, 100UL );
3232
FD_TEST( bloom->keys_len==1UL );
3333
FD_TEST( bloom->bits_len==100UL );
34+
35+
free( bytes );
3436
}
3537

3638
void
@@ -53,6 +55,8 @@ test_add_contains( void ) {
5355
FD_TEST( !fd_bloom_contains( bloom, (uchar *)"world", 5UL ) );
5456
fd_bloom_insert( bloom, (uchar *)"world", 5UL );
5557
FD_TEST( fd_bloom_contains( bloom, (uchar *)"world", 5UL ) );
58+
59+
free( bytes );
5660
}
5761

5862
int

0 commit comments

Comments
 (0)