mirror of
https://github.com/systemd/systemd.git
synced 2024-10-26 08:55:40 +03:00
refactor: replace sizeof in loop with ELEMENTSOF & FOREACH_ELEMENT (#34863)
This commit is contained in:
parent
4d5d574906
commit
b6b8527cd1
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "gunicode.h"
|
||||
#include "macro.h"
|
||||
|
||||
#define unichar uint32_t
|
||||
|
||||
@ -92,7 +93,7 @@ unichar_iswide (unichar c)
|
||||
{0x20000, 0x2FFFD}, {0x30000, 0x3FFFD},
|
||||
};
|
||||
|
||||
if (bsearch ((void *)(uintptr_t)c, wide, (sizeof (wide) / sizeof ((wide)[0])), sizeof wide[0],
|
||||
if (bsearch ((void *)(uintptr_t)c, wide, ELEMENTSOF(wide), sizeof wide[0],
|
||||
interval_compare))
|
||||
return true;
|
||||
|
||||
|
@ -74,16 +74,15 @@ TEST(tpm2_util_pbkdf2_hmac_sha256) {
|
||||
};
|
||||
|
||||
uint8_t res[SHA256_DIGEST_SIZE];
|
||||
for (size_t i = 0; i < sizeof(test_vectors)/sizeof(test_vectors[0]); i++) {
|
||||
|
||||
FOREACH_ELEMENT(vector, test_vectors) {
|
||||
int rc = tpm2_util_pbkdf2_hmac_sha256(
|
||||
test_vectors[i].pass,
|
||||
test_vectors[i].passlen,
|
||||
test_vectors[i].salt,
|
||||
test_vectors[i].saltlen,
|
||||
vector->pass,
|
||||
vector->passlen,
|
||||
vector->salt,
|
||||
vector->saltlen,
|
||||
res);
|
||||
assert_se(rc == 0);
|
||||
assert_se(memcmp(test_vectors[i].expected, res, SHA256_DIGEST_SIZE) == 0);
|
||||
assert_se(memcmp(vector->expected, res, SHA256_DIGEST_SIZE) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -557,7 +557,6 @@ static int do_scsi_page83_inquiry(struct scsi_id_device *dev_scsi, int fd,
|
||||
char *unit_serial_number, char *wwn,
|
||||
char *wwn_vendor_extension, char *tgpt_group) {
|
||||
int retval;
|
||||
unsigned id_ind, j;
|
||||
unsigned char page_83[SCSI_INQ_BUFF_LEN];
|
||||
|
||||
/* also pick up the page 80 serial number */
|
||||
@ -611,16 +610,14 @@ static int do_scsi_page83_inquiry(struct scsi_id_device *dev_scsi, int fd,
|
||||
* Search for a match in the prioritized id_search_list - since WWN ids
|
||||
* come first we can pick up the WWN in check_fill_0x83_id().
|
||||
*/
|
||||
for (id_ind = 0;
|
||||
id_ind < sizeof(id_search_list)/sizeof(id_search_list[0]);
|
||||
id_ind++) {
|
||||
FOREACH_ELEMENT(search_value, id_search_list) {
|
||||
/*
|
||||
* Examine each descriptor returned. There is normally only
|
||||
* one or a small number of descriptors.
|
||||
*/
|
||||
for (j = 4; j <= ((unsigned)page_83[2] << 8) + (unsigned)page_83[3] + 3; j += page_83[j + 3] + 4) {
|
||||
for (unsigned j = 4; j <= ((unsigned)page_83[2] << 8) + (unsigned)page_83[3] + 3; j += page_83[j + 3] + 4) {
|
||||
retval = check_fill_0x83_id(dev_scsi, page_83 + j,
|
||||
id_search_list + id_ind,
|
||||
search_value,
|
||||
serial, serial_short, len,
|
||||
wwn, wwn_vendor_extension,
|
||||
tgpt_group);
|
||||
|
@ -356,7 +356,7 @@ static bool test_key(
|
||||
i * BITS_PER_LONG, yes_no(found));
|
||||
}
|
||||
/* If there are no keys in the lower block, check the higher blocks */
|
||||
for (size_t block = 0; block < sizeof(high_key_blocks) / sizeof(struct range) && !found; block++)
|
||||
for (size_t block = 0; block < ELEMENTSOF(high_key_blocks) && !found; block++)
|
||||
for (unsigned i = high_key_blocks[block].start; i < high_key_blocks[block].end && !found; i++)
|
||||
if (test_bit(i, bitmask_key)) {
|
||||
log_device_debug(dev, "test_key: Found key %x in high block", i);
|
||||
|
Loading…
Reference in New Issue
Block a user