use memcpy/memcmp instead of str-functions where applicable

This commit is contained in:
Christian Grothoff 2020-03-01 13:36:40 +01:00
parent 1eb292fe1f
commit f457e1332d
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC

View File

@ -200,7 +200,7 @@ static const struct CountryTableEntry country_table[] = {
* *
* @param ptr1 pointer to a `struct table_entry` * @param ptr1 pointer to a `struct table_entry`
* @param ptr2 pointer to a `struct table_entry` * @param ptr2 pointer to a `struct table_entry`
* @return result of strncmp()'ing the 2-digit country codes of the entries * @return result of memcmp()'ing the 2-digit country codes of the entries
*/ */
static int static int
cmp_country_code (const void *ptr1, cmp_country_code (const void *ptr1,
@ -209,7 +209,7 @@ cmp_country_code (const void *ptr1,
const struct CountryTableEntry *cc1 = ptr1; const struct CountryTableEntry *cc1 = ptr1;
const struct CountryTableEntry *cc2 = ptr2; const struct CountryTableEntry *cc2 = ptr2;
return strncmp (cc1->code, return memcmp (cc1->code,
cc2->code, cc2->code,
2); 2);
} }
@ -242,9 +242,9 @@ validate_iban (const char *iban)
"IBAN number too long to be valid\n"); "IBAN number too long to be valid\n");
return GNUNET_NO; return GNUNET_NO;
} }
strncpy (cc, iban, 2); memcpy (cc, iban, 2);
strncpy (ibancpy, iban + 4, len - 4); memcpy (ibancpy, iban + 4, len - 4);
strncpy (ibancpy + len - 4, iban, 4); memcpy (ibancpy + len - 4, iban, 4);
ibancpy[len] = '\0'; ibancpy[len] = '\0';
cc_entry.code = cc; cc_entry.code = cc;
cc_entry.english = NULL; cc_entry.english = NULL;
@ -303,12 +303,15 @@ validate_iban (const char *iban)
remainder = dividend % 97; remainder = dividend % 97;
} }
GNUNET_free (nbuf); GNUNET_free (nbuf);
if (1 == remainder) if (1 != remainder)
return GNUNET_YES; {
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"IBAN checksum wrong\n"); "IBAN `%s' has the wrong checksum\n",
iban);
return GNUNET_NO; return GNUNET_NO;
} }
return GNUNET_YES;
}
/** /**