Fixed usage of 8-bit modulo operator off-by-one maximum. (#901)

This commit is contained in:
Steve Karg
2025-02-04 13:56:53 -06:00
committed by GitHub
parent 19ef7f74cd
commit 77bdaaf853
5 changed files with 7 additions and 7 deletions
+1 -1
View File
@@ -474,7 +474,7 @@ void Device_UUID_Init(void)
/* 1. Generate 16 random bytes = 128 bits */
for (i = 0; i < sizeof(Device_UUID); i++) {
Device_UUID[i] = rand() % 255;
Device_UUID[i] = rand() % 256;
}
/* 2. Adjust certain bits according to RFC 4122 section 4.4.
This just means do the following
+2 -2
View File
@@ -97,7 +97,7 @@ void bsc_generate_random_vmac(BACNET_SC_VMAC_ADDRESS *p)
int i;
for (i = 0; i < BVLC_SC_VMAC_SIZE; i++) {
p->address[i] = rand() % 255;
p->address[i] = rand() % 256;
if (i == 0) {
/* According H.7.3 EUI-48 and Random-48 VMAC Address:
The Random-48 VMAC is a 6-octet VMAC address in which the least
@@ -120,7 +120,7 @@ void bsc_generate_random_uuid(BACNET_SC_UUID *p)
int i;
for (i = 0; i < BVLC_SC_UUID_SIZE; i++) {
p->uuid[i] = rand() % 255;
p->uuid[i] = rand() % 256;
}
debug_printf_hex(0, p->uuid, BVLC_SC_UUID_SIZE, "bsc_generate_random_uuid");
}
+1 -1
View File
@@ -1352,7 +1352,7 @@ void MSTP_Zero_Config_UUID_Init(struct mstp_port_struct_t *mstp_port)
}
/* 1. Generate 16 random bytes = 128 bits */
for (i = 0; i < MSTP_UUID_SIZE; i++) {
mstp_port->UUID[i] = rand() % 255;
mstp_port->UUID[i] = rand() % 256;
}
/* 2. Adjust certain bits according to RFC 4122 section 4.4.
This just means do the following
+2 -2
View File
@@ -45,7 +45,7 @@ static void testRingAroundBuffer(
/* test the ring around the buffer */
for (index = 0; index < element_count; index++) {
for (count = 1; count < 4; count++) {
value = (index * count) % 255;
value = (index * count) % 256;
for (data_index = 0; data_index < element_size; data_index++) {
data_element[data_index] = value;
}
@@ -54,7 +54,7 @@ static void testRingAroundBuffer(
zassert_equal(Ringbuf_Count(test_buffer), count, NULL);
}
for (count = 1; count < 4; count++) {
value = (index * count) % 255;
value = (index * count) % 256;
test_data = Ringbuf_Peek(test_buffer);
zassert_not_null(test_data, NULL);
if (test_data) {
+1 -1
View File
@@ -38,7 +38,7 @@ static void test_COBS_Encode_Decode(void)
size_t encoded_buffer_length, test_buffer_length;
for (i = 2; i < sizeof(buffer); i++) {
buffer[i] = i % 0xff;
buffer[i] = i % 256;
}
encoded_buffer_length = cobs_frame_encode(
encoded_buffer, sizeof(encoded_buffer), buffer, sizeof(buffer));