mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
cleanup: Use static_assert
instead of preprocessor #error
.
`ccompat.h` ensures that if it doesn't exist, then `static_assert` has no effect.
This commit is contained in:
parent
edf9d66717
commit
2bc83a4b51
|
@ -24,6 +24,11 @@
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
//!TOKSTYLE-
|
||||||
|
static_assert(MAX_CONCURRENT_FILE_PIPES <= UINT8_MAX + 1,
|
||||||
|
"uint8_t cannot represent all file transfer numbers");
|
||||||
|
//!TOKSTYLE+
|
||||||
|
|
||||||
static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data,
|
static int write_cryptpacket_id(const Messenger *m, int32_t friendnumber, uint8_t packet_id, const uint8_t *data,
|
||||||
uint32_t length, uint8_t congestion_control);
|
uint32_t length, uint8_t congestion_control);
|
||||||
static void m_register_default_plugins(Messenger *m);
|
static void m_register_default_plugins(Messenger *m);
|
||||||
|
|
|
@ -24,10 +24,6 @@
|
||||||
/* This cannot be bigger than 256 */
|
/* This cannot be bigger than 256 */
|
||||||
#define MAX_CONCURRENT_FILE_PIPES 256
|
#define MAX_CONCURRENT_FILE_PIPES 256
|
||||||
|
|
||||||
#if !defined(__SPLINT__) && MAX_CONCURRENT_FILE_PIPES > UINT8_MAX + 1
|
|
||||||
#error "uint8_t cannot represent all file transfer numbers"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#define FRIEND_ADDRESS_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint32_t) + sizeof(uint16_t))
|
#define FRIEND_ADDRESS_SIZE (CRYPTO_PUBLIC_KEY_SIZE + sizeof(uint32_t) + sizeof(uint16_t))
|
||||||
|
|
||||||
|
|
|
@ -194,13 +194,12 @@ static int inet_pton6(const char *addrString, struct in6_addr *addrbuf)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if TOX_INET6_ADDRSTRLEN < INET6_ADDRSTRLEN
|
//!TOKSTYLE-
|
||||||
#error "TOX_INET6_ADDRSTRLEN should be greater or equal to INET6_ADDRSTRLEN (#INET6_ADDRSTRLEN)"
|
static_assert(TOX_INET6_ADDRSTRLEN >= INET6_ADDRSTRLEN,
|
||||||
#endif
|
"TOX_INET6_ADDRSTRLEN should be greater or equal to INET6_ADDRSTRLEN (#INET6_ADDRSTRLEN)");
|
||||||
|
static_assert(TOX_INET_ADDRSTRLEN >= INET_ADDRSTRLEN,
|
||||||
#if TOX_INET_ADDRSTRLEN < INET_ADDRSTRLEN
|
"TOX_INET_ADDRSTRLEN should be greater or equal to INET_ADDRSTRLEN (#INET_ADDRSTRLEN)");
|
||||||
#error "TOX_INET_ADDRSTRLEN should be greater or equal to INET_ADDRSTRLEN (#INET_ADDRSTRLEN)"
|
//!TOKSTYLE+
|
||||||
#endif
|
|
||||||
|
|
||||||
static int make_proto(int proto)
|
static int make_proto(int proto)
|
||||||
{
|
{
|
||||||
|
|
|
@ -26,6 +26,11 @@
|
||||||
#define DATA_REQUEST_MIN_SIZE ONION_DATA_REQUEST_MIN_SIZE
|
#define DATA_REQUEST_MIN_SIZE ONION_DATA_REQUEST_MIN_SIZE
|
||||||
#define DATA_REQUEST_MIN_SIZE_RECV (DATA_REQUEST_MIN_SIZE + ONION_RETURN_3)
|
#define DATA_REQUEST_MIN_SIZE_RECV (DATA_REQUEST_MIN_SIZE + ONION_RETURN_3)
|
||||||
|
|
||||||
|
//!TOKSTYLE-
|
||||||
|
static_assert(ONION_PING_ID_SIZE == CRYPTO_PUBLIC_KEY_SIZE,
|
||||||
|
"announce response packets assume that ONION_PING_ID_SIZE is equal to CRYPTO_PUBLIC_KEY_SIZE");
|
||||||
|
//!TOKSTYLE+
|
||||||
|
|
||||||
typedef struct Onion_Announce_Entry {
|
typedef struct Onion_Announce_Entry {
|
||||||
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
uint8_t public_key[CRYPTO_PUBLIC_KEY_SIZE];
|
||||||
IP_Port ret_ip_port;
|
IP_Port ret_ip_port;
|
||||||
|
|
|
@ -25,10 +25,6 @@
|
||||||
|
|
||||||
#define ONION_DATA_RESPONSE_MIN_SIZE (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE)
|
#define ONION_DATA_RESPONSE_MIN_SIZE (1 + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE)
|
||||||
|
|
||||||
#if ONION_PING_ID_SIZE != CRYPTO_PUBLIC_KEY_SIZE
|
|
||||||
#error "announce response packets assume that ONION_PING_ID_SIZE is equal to CRYPTO_PUBLIC_KEY_SIZE"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ONION_DATA_REQUEST_MIN_SIZE (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE)
|
#define ONION_DATA_REQUEST_MIN_SIZE (1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_NONCE_SIZE + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE)
|
||||||
#define MAX_DATA_REQUEST_SIZE (ONION_MAX_DATA_SIZE - ONION_DATA_REQUEST_MIN_SIZE)
|
#define MAX_DATA_REQUEST_SIZE (ONION_MAX_DATA_SIZE - ONION_DATA_REQUEST_MIN_SIZE)
|
||||||
|
|
||||||
|
|
|
@ -32,37 +32,24 @@
|
||||||
|
|
||||||
#define SET_ERROR_PARAMETER(param, x) do { if (param) { *param = x; } } while (0)
|
#define SET_ERROR_PARAMETER(param, x) do { if (param) { *param = x; } } while (0)
|
||||||
|
|
||||||
#if TOX_HASH_LENGTH != CRYPTO_SHA256_SIZE
|
//!TOKSTYLE-
|
||||||
#error "TOX_HASH_LENGTH is assumed to be equal to CRYPTO_SHA256_SIZE"
|
static_assert(TOX_HASH_LENGTH == CRYPTO_SHA256_SIZE,
|
||||||
#endif
|
"TOX_HASH_LENGTH is assumed to be equal to CRYPTO_SHA256_SIZE");
|
||||||
|
static_assert(FILE_ID_LENGTH == CRYPTO_SYMMETRIC_KEY_SIZE,
|
||||||
#if FILE_ID_LENGTH != CRYPTO_SYMMETRIC_KEY_SIZE
|
"FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE");
|
||||||
#error "FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE"
|
static_assert(TOX_FILE_ID_LENGTH == CRYPTO_SYMMETRIC_KEY_SIZE,
|
||||||
#endif
|
"TOX_FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE");
|
||||||
|
static_assert(TOX_FILE_ID_LENGTH == TOX_HASH_LENGTH,
|
||||||
#if TOX_FILE_ID_LENGTH != CRYPTO_SYMMETRIC_KEY_SIZE
|
"TOX_FILE_ID_LENGTH is assumed to be equal to TOX_HASH_LENGTH");
|
||||||
#error "TOX_FILE_ID_LENGTH is assumed to be equal to CRYPTO_SYMMETRIC_KEY_SIZE"
|
static_assert(TOX_PUBLIC_KEY_SIZE == CRYPTO_PUBLIC_KEY_SIZE,
|
||||||
#endif
|
"TOX_PUBLIC_KEY_SIZE is assumed to be equal to CRYPTO_PUBLIC_KEY_SIZE");
|
||||||
|
static_assert(TOX_SECRET_KEY_SIZE == CRYPTO_SECRET_KEY_SIZE,
|
||||||
#if TOX_FILE_ID_LENGTH != TOX_HASH_LENGTH
|
"TOX_SECRET_KEY_SIZE is assumed to be equal to CRYPTO_SECRET_KEY_SIZE");
|
||||||
#error "TOX_FILE_ID_LENGTH is assumed to be equal to TOX_HASH_LENGTH"
|
static_assert(TOX_MAX_NAME_LENGTH == MAX_NAME_LENGTH,
|
||||||
#endif
|
"TOX_MAX_NAME_LENGTH is assumed to be equal to MAX_NAME_LENGTH");
|
||||||
|
static_assert(TOX_MAX_STATUS_MESSAGE_LENGTH == MAX_STATUSMESSAGE_LENGTH,
|
||||||
#if TOX_PUBLIC_KEY_SIZE != CRYPTO_PUBLIC_KEY_SIZE
|
"TOX_MAX_STATUS_MESSAGE_LENGTH is assumed to be equal to MAX_STATUSMESSAGE_LENGTH");
|
||||||
#error "TOX_PUBLIC_KEY_SIZE is assumed to be equal to CRYPTO_PUBLIC_KEY_SIZE"
|
//!TOKSTYLE+
|
||||||
#endif
|
|
||||||
|
|
||||||
#if TOX_SECRET_KEY_SIZE != CRYPTO_SECRET_KEY_SIZE
|
|
||||||
#error "TOX_SECRET_KEY_SIZE is assumed to be equal to CRYPTO_SECRET_KEY_SIZE"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if TOX_MAX_NAME_LENGTH != MAX_NAME_LENGTH
|
|
||||||
#error "TOX_MAX_NAME_LENGTH is assumed to be equal to MAX_NAME_LENGTH"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if TOX_MAX_STATUS_MESSAGE_LENGTH != MAX_STATUSMESSAGE_LENGTH
|
|
||||||
#error "TOX_MAX_STATUS_MESSAGE_LENGTH is assumed to be equal to MAX_STATUSMESSAGE_LENGTH"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct Tox {
|
struct Tox {
|
||||||
// XXX: Messenger *must* be the first member, because toxav casts its
|
// XXX: Messenger *must* be the first member, because toxav casts its
|
||||||
|
|
Loading…
Reference in New Issue
Block a user