зеркало из https://github.com/github/putty.git
Replace all 'sizeof(x)/sizeof(*x)' with lenof.
I noticed a few of these in the course of preparing the previous commit. I must have been writing that idiom out by hand for _ages_ before it became totally habitual to #define it as 'lenof' in every codebase I touch. Now I've gone through and replaced all the old verbosity with nice terse lenofs.
This commit is contained in:
Родитель
35690040fd
Коммит
0b14e7376e
6
psftp.c
6
psftp.c
|
@ -2116,7 +2116,7 @@ const struct sftp_cmd_lookup *lookup_command(const char *name)
|
|||
int i, j, k, cmp;
|
||||
|
||||
i = -1;
|
||||
j = sizeof(sftp_lookup) / sizeof(*sftp_lookup);
|
||||
j = lenof(sftp_lookup);
|
||||
while (j - i > 1) {
|
||||
k = (j + i) / 2;
|
||||
cmp = strcmp(name, sftp_lookup[k].name);
|
||||
|
@ -2140,7 +2140,7 @@ static int sftp_cmd_help(struct sftp_command *cmd)
|
|||
*/
|
||||
int maxlen;
|
||||
maxlen = 0;
|
||||
for (i = 0; i < sizeof(sftp_lookup) / sizeof(*sftp_lookup); i++) {
|
||||
for (i = 0; i < lenof(sftp_lookup); i++) {
|
||||
int len;
|
||||
if (!sftp_lookup[i].listed)
|
||||
continue;
|
||||
|
@ -2148,7 +2148,7 @@ static int sftp_cmd_help(struct sftp_command *cmd)
|
|||
if (maxlen < len)
|
||||
maxlen = len;
|
||||
}
|
||||
for (i = 0; i < sizeof(sftp_lookup) / sizeof(*sftp_lookup); i++) {
|
||||
for (i = 0; i < lenof(sftp_lookup); i++) {
|
||||
const struct sftp_cmd_lookup *lookup;
|
||||
if (!sftp_lookup[i].listed)
|
||||
continue;
|
||||
|
|
3
sftp.c
3
sftp.c
|
@ -213,8 +213,7 @@ static int fxp_got_status(struct sftp_packet *pktin)
|
|||
fxp_error_message = "malformed FXP_STATUS packet";
|
||||
fxp_errtype = -1;
|
||||
} else {
|
||||
if (fxp_errtype < 0 ||
|
||||
fxp_errtype >= sizeof(messages) / sizeof(*messages))
|
||||
if (fxp_errtype < 0 || fxp_errtype >= lenof(messages))
|
||||
fxp_error_message = "unknown error code";
|
||||
else
|
||||
fxp_error_message = messages[fxp_errtype];
|
||||
|
|
5
sshaes.c
5
sshaes.c
|
@ -1157,10 +1157,7 @@ static const ssh2_cipheralg *const aes_list[] = {
|
|||
&ssh_aes128,
|
||||
};
|
||||
|
||||
const ssh2_ciphers ssh2_aes = {
|
||||
sizeof(aes_list) / sizeof(*aes_list),
|
||||
aes_list
|
||||
};
|
||||
const ssh2_ciphers ssh2_aes = { lenof(aes_list), aes_list };
|
||||
|
||||
/*
|
||||
* Implementation of AES for PuTTY using AES-NI
|
||||
|
|
|
@ -124,7 +124,4 @@ static const ssh2_cipheralg *const arcfour_list[] = {
|
|||
&ssh_arcfour128_ssh2,
|
||||
};
|
||||
|
||||
const ssh2_ciphers ssh2_arcfour = {
|
||||
sizeof(arcfour_list) / sizeof(*arcfour_list),
|
||||
arcfour_list
|
||||
};
|
||||
const ssh2_ciphers ssh2_arcfour = { lenof(arcfour_list), arcfour_list };
|
||||
|
|
|
@ -702,7 +702,4 @@ static const ssh2_cipheralg *const blowfish_list[] = {
|
|||
&ssh_blowfish_ssh2
|
||||
};
|
||||
|
||||
const ssh2_ciphers ssh2_blowfish = {
|
||||
sizeof(blowfish_list) / sizeof(*blowfish_list),
|
||||
blowfish_list
|
||||
};
|
||||
const ssh2_ciphers ssh2_blowfish = { lenof(blowfish_list), blowfish_list };
|
||||
|
|
5
sshccp.c
5
sshccp.c
|
@ -1047,7 +1047,4 @@ static const ssh2_cipheralg *const ccp_list[] = {
|
|||
&ssh2_chacha20_poly1305
|
||||
};
|
||||
|
||||
const ssh2_ciphers ssh2_ccp = {
|
||||
sizeof(ccp_list) / sizeof(*ccp_list),
|
||||
ccp_list
|
||||
};
|
||||
const ssh2_ciphers ssh2_ccp = { lenof(ccp_list), ccp_list };
|
||||
|
|
10
sshdes.c
10
sshdes.c
|
@ -1115,20 +1115,14 @@ static const ssh2_cipheralg *const des3_list[] = {
|
|||
&ssh_3des_ssh2
|
||||
};
|
||||
|
||||
const ssh2_ciphers ssh2_3des = {
|
||||
sizeof(des3_list) / sizeof(*des3_list),
|
||||
des3_list
|
||||
};
|
||||
const ssh2_ciphers ssh2_3des = { lenof(des3_list), des3_list };
|
||||
|
||||
static const ssh2_cipheralg *const des_list[] = {
|
||||
&ssh_des_ssh2,
|
||||
&ssh_des_sshcom_ssh2
|
||||
};
|
||||
|
||||
const ssh2_ciphers ssh2_des = {
|
||||
sizeof(des_list) / sizeof(*des_list),
|
||||
des_list
|
||||
};
|
||||
const ssh2_ciphers ssh2_des = { lenof(des_list), des_list };
|
||||
|
||||
const ssh1_cipheralg ssh1_3des = {
|
||||
des3_ssh1_new, des3_ssh1_free, des3_ssh1_sesskey,
|
||||
|
|
16
sshdh.c
16
sshdh.c
|
@ -42,10 +42,7 @@ static const ssh_kex *const group1_list[] = {
|
|||
&ssh_diffiehellman_group1_sha1
|
||||
};
|
||||
|
||||
const ssh_kexes ssh_diffiehellman_group1 = {
|
||||
sizeof(group1_list) / sizeof(*group1_list),
|
||||
group1_list
|
||||
};
|
||||
const ssh_kexes ssh_diffiehellman_group1 = { lenof(group1_list), group1_list };
|
||||
|
||||
static const struct dh_extra extra_group14 = {
|
||||
false, dh_group14_construct,
|
||||
|
@ -67,8 +64,7 @@ static const ssh_kex *const group14_list[] = {
|
|||
};
|
||||
|
||||
const ssh_kexes ssh_diffiehellman_group14 = {
|
||||
sizeof(group14_list) / sizeof(*group14_list),
|
||||
group14_list
|
||||
lenof(group14_list), group14_list
|
||||
};
|
||||
|
||||
static const struct dh_extra extra_gex = { true };
|
||||
|
@ -88,10 +84,7 @@ static const ssh_kex *const gex_list[] = {
|
|||
&ssh_diffiehellman_gex_sha1
|
||||
};
|
||||
|
||||
const ssh_kexes ssh_diffiehellman_gex = {
|
||||
sizeof(gex_list) / sizeof(*gex_list),
|
||||
gex_list
|
||||
};
|
||||
const ssh_kexes ssh_diffiehellman_gex = { lenof(gex_list), gex_list };
|
||||
|
||||
/*
|
||||
* Suffix on GSSAPI SSH protocol identifiers that indicates Kerberos 5
|
||||
|
@ -129,8 +122,7 @@ static const ssh_kex *const gssk5_sha1_kex_list[] = {
|
|||
};
|
||||
|
||||
const ssh_kexes ssh_gssk5_sha1_kex = {
|
||||
sizeof(gssk5_sha1_kex_list) / sizeof(*gssk5_sha1_kex_list),
|
||||
gssk5_sha1_kex_list
|
||||
lenof(gssk5_sha1_kex_list), gssk5_sha1_kex_list
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
5
sshecc.c
5
sshecc.c
|
@ -1444,10 +1444,7 @@ static const ssh_kex *const ec_kex_list[] = {
|
|||
&ssh_ec_kex_nistp521,
|
||||
};
|
||||
|
||||
const ssh_kexes ssh_ecdh_kex = {
|
||||
sizeof(ec_kex_list) / sizeof(*ec_kex_list),
|
||||
ec_kex_list
|
||||
};
|
||||
const ssh_kexes ssh_ecdh_kex = { lenof(ec_kex_list), ec_kex_list };
|
||||
|
||||
/* ----------------------------------------------------------------------
|
||||
* Helper functions for finding key algorithms and returning auxiliary
|
||||
|
|
|
@ -140,7 +140,7 @@ static void random_stir(void)
|
|||
* digest.
|
||||
*/
|
||||
|
||||
for (k = 0; k < sizeof(digest) / sizeof(*digest); k++)
|
||||
for (k = 0; k < lenof(digest); k++)
|
||||
digest[k] ^= ((uint32_t *) (pool.pool + j))[k];
|
||||
|
||||
/*
|
||||
|
@ -153,7 +153,7 @@ static void random_stir(void)
|
|||
* Stick the result back into the pool.
|
||||
*/
|
||||
|
||||
for (k = 0; k < sizeof(digest) / sizeof(*digest); k++)
|
||||
for (k = 0; k < lenof(digest); k++)
|
||||
((uint32_t *) (pool.pool + j))[k] = digest[k];
|
||||
}
|
||||
|
||||
|
|
5
sshrsa.c
5
sshrsa.c
|
@ -927,7 +927,4 @@ static const ssh_kex *const rsa_kex_list[] = {
|
|||
&ssh_rsa_kex_sha1
|
||||
};
|
||||
|
||||
const ssh_kexes ssh_rsa_kex = {
|
||||
sizeof(rsa_kex_list) / sizeof(*rsa_kex_list),
|
||||
rsa_kex_list
|
||||
};
|
||||
const ssh_kexes ssh_rsa_kex = { lenof(rsa_kex_list), rsa_kex_list };
|
||||
|
|
|
@ -360,7 +360,7 @@ int main(void) {
|
|||
|
||||
errors = 0;
|
||||
|
||||
for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) {
|
||||
for (i = 0; i < lenof(tests); i++) {
|
||||
SHA256_Simple(tests[i].teststring,
|
||||
strlen(tests[i].teststring), digest);
|
||||
for (j = 0; j < 32; j++) {
|
||||
|
|
|
@ -407,7 +407,7 @@ int main(void) {
|
|||
|
||||
errors = 0;
|
||||
|
||||
for (i = 0; i < sizeof(tests) / sizeof(*tests); i++) {
|
||||
for (i = 0; i < lenof(tests); i++) {
|
||||
if (tests[i].teststring) {
|
||||
SHA512_Simple(tests[i].teststring,
|
||||
strlen(tests[i].teststring), digest);
|
||||
|
|
|
@ -510,7 +510,7 @@ static void zlib_match(struct LZ77Context *ectx, int distance, int len)
|
|||
* transmitting.
|
||||
*/
|
||||
i = -1;
|
||||
j = sizeof(lencodes) / sizeof(*lencodes);
|
||||
j = lenof(lencodes);
|
||||
while (1) {
|
||||
assert(j - i >= 2);
|
||||
k = (j + i) / 2;
|
||||
|
@ -546,7 +546,7 @@ static void zlib_match(struct LZ77Context *ectx, int distance, int len)
|
|||
* transmitting.
|
||||
*/
|
||||
i = -1;
|
||||
j = sizeof(distcodes) / sizeof(*distcodes);
|
||||
j = lenof(distcodes);
|
||||
while (1) {
|
||||
assert(j - i >= 2);
|
||||
k = (j + i) / 2;
|
||||
|
|
Загрузка…
Ссылка в новой задаче