}
msg->data.ntp_source.type = htonl(type);
- if (strlen(data.name) >= sizeof (msg->data.ntp_source.name))
- assert(0);
+ BRIEF_ASSERT(strlen(data.name) < sizeof (msg->data.ntp_source.name));
strncpy((char *)msg->data.ntp_source.name, data.name,
sizeof (msg->data.ntp_source.name));
msg->data.ntp_source.port = htonl(data.port);
request.command = htons(i);
request_length = PKL_CommandLength(&request);
padding_length = PKL_CommandPaddingLength(&request);
- if (padding_length > MAX_PADDING_LENGTH || padding_length > request_length ||
- request_length > sizeof (CMD_Request) ||
- (request_length && request_length < offsetof(CMD_Request, data)))
- assert(0);
+ BRIEF_ASSERT(padding_length <= MAX_PADDING_LENGTH && padding_length <= request_length &&
+ request_length <= sizeof (CMD_Request) &&
+ (request_length == 0 || request_length >= offsetof(CMD_Request, data)));
}
for (i = 1; i < N_REPLY_TYPES; i++) {
reply.reply = htons(i);
reply.status = STT_SUCCESS;
reply_length = PKL_ReplyLength(&reply);
- if ((reply_length && reply_length < offsetof(CMD_Reply, data)) ||
- reply_length > sizeof (CMD_Reply))
- assert(0);
+ BRIEF_ASSERT((reply_length == 0 || reply_length >= offsetof(CMD_Reply, data)) &&
+ reply_length <= sizeof (CMD_Reply));
}
}
*paths = ARR_GetElements(nts_trusted_certs_paths);
*ids = ARR_GetElements(nts_trusted_certs_ids);
- if (ARR_GetSize(nts_trusted_certs_paths) != ARR_GetSize(nts_trusted_certs_ids))
- assert(0);
+ BRIEF_ASSERT(ARR_GetSize(nts_trusted_certs_paths) == ARR_GetSize(nts_trusted_certs_ids));
return ARR_GetSize(nts_trusted_certs_paths);
}
LCL_Finalise(void)
{
/* Make sure all handlers have been removed */
- if (change_list.next != &change_list)
- assert(0);
- if (dispersion_notify_list.next != &dispersion_notify_list)
- assert(0);
+ BRIEF_ASSERT(change_list.next == &change_list);
+ BRIEF_ASSERT(dispersion_notify_list.next == &dispersion_notify_list);
}
/* ================================================== */
/* Check that the handler is not already registered */
for (ptr = change_list.next; ptr != &change_list; ptr = ptr->next) {
- if (!(ptr->handler != handler || ptr->anything != anything)) {
- assert(0);
- }
+ BRIEF_ASSERT(ptr->handler != handler || ptr->anything != anything);
}
new_entry = MallocNew(ChangeListEntry);
/* Check that the handler is not already registered */
for (ptr = dispersion_notify_list.next; ptr != &dispersion_notify_list; ptr = ptr->next) {
- if (!(ptr->handler != handler || ptr->anything != anything)) {
- assert(0);
- }
+ BRIEF_ASSERT(ptr->handler != handler || ptr->anything != anything);
}
new_entry = MallocNew(DispersionNotifyListEntry);
inst->valid_rx = 1;
}
- if ((unsigned int)local_receive.source >= sizeof (tss_chars) ||
- (unsigned int)local_transmit.source >= sizeof (tss_chars))
- assert(0);
+ BRIEF_ASSERT((unsigned int)local_receive.source < sizeof (tss_chars) &&
+ (unsigned int)local_transmit.source < sizeof (tss_chars));
DEBUG_LOG("NTP packet lvm=%o stratum=%d poll=%d prec=%d root_delay=%.9f root_disp=%.9f refid=%"PRIx32" [%s]",
message->lvm, message->stratum, message->poll, message->precision,
if (replacement)
record->resolved_addr = new_addr->ip_addr;
- if (record->remote_addr != NCR_GetRemoteAddress(record->data) ||
- UTI_CompareIPs(&record->remote_addr->ip_addr, &new_addr->ip_addr, NULL) != 0)
- assert(0);
+ BRIEF_ASSERT(record->remote_addr == NCR_GetRemoteAddress(record->data) &&
+ UTI_CompareIPs(&record->remote_addr->ip_addr, &new_addr->ip_addr, NULL) == 0);
if (!UTI_IsIPReal(&old_addr->ip_addr) && UTI_IsIPReal(&new_addr->ip_addr)) {
if (auto_start_sources)
ServerKey *key;
int key_length;
- if (index < 0 || index >= MAX_SERVER_KEYS)
- assert(0);
+ BRIEF_ASSERT(index >= 0 && index < MAX_SERVER_KEYS);
/* Prefer AES-128-GCM-SIV if available. Note that if older keys loaded
from ntsdumpdir use a different algorithm, responding to NTP requests
key = &server_keys[index];
key_length = SIV_GetKeyLength(algorithm);
- if (key_length > sizeof (key->key))
- assert(0);
+ BRIEF_ASSERT(key_length <= sizeof (key->key));
UTI_GetRandomBytesUrandom(key->key, key_length);
memset(key->key + key_length, 0, sizeof (key->key) - key_length);
header->key_id = htonl(key->id);
nonce = cookie->cookie + sizeof (*header);
- if (key->nonce_length > sizeof (cookie->cookie) - sizeof (*header))
- assert(0);
+ BRIEF_ASSERT(key->nonce_length <= sizeof (cookie->cookie) - sizeof (*header));
UTI_GetRandomBytes(nonce, key->nonce_length);
plaintext_length = context->c2s.length + context->s2c.length;
goto error;
if (certs && keys) {
- if (trusted_certs || trusted_certs_ids)
- assert(0);
+ BRIEF_ASSERT(!trusted_certs && !trusted_certs_ids);
for (i = 0; i < n_certs_keys; i++) {
if (!UTI_CheckFilePermissions(keys[i], 0771))
goto error;
}
} else {
- if (certs || keys || n_certs_keys > 0)
- assert(0);
+ BRIEF_ASSERT(!certs && !keys && n_certs_keys <= 0);
if (trusted_cert_set == 0 && !CNF_GetNoSystemCert()) {
r = gnutls_certificate_set_x509_system_trust(credentials);
body = (unsigned char *)(header + 1);
ciphertext = body + nonce_length + nonce_padding;
- if ((unsigned char *)header + auth_length !=
- ciphertext + ciphertext_length + ciphertext_padding + additional_padding)
- assert(0);
+ BRIEF_ASSERT((unsigned char *)header + auth_length ==
+ ciphertext + ciphertext_length + ciphertext_padding + additional_padding);
memcpy(body, nonce, nonce_length);
memset(body + nonce_length, 0, nonce_padding);
/* Make sure this is a response to the request from the last call
of NNS_CheckRequestAuth() */
- if (UTI_CompareNtp64(&server->req_tx, &request->transmit_ts) != 0)
- assert(0);
+ BRIEF_ASSERT(UTI_CompareNtp64(&server->req_tx, &request->transmit_ts) == 0);
for (parsed = NTP_HEADER_LENGTH; parsed < req_info->length; parsed += ef_length) {
if (!NEF_ParseField(request, req_info->length, parsed,
PrvResponse res;
SCK_SockaddrToIPSockAddr(address, address_len, &ip_saddr);
- if (ip_saddr.port != 0 && ip_saddr.port != CNF_GetNTPPort() &&
- ip_saddr.port != CNF_GetAcquisitionPort() && ip_saddr.port != CNF_GetPtpPort())
- assert(0);
+ BRIEF_ASSERT(ip_saddr.port == 0 || ip_saddr.port == CNF_GetNTPPort() ||
+ ip_saddr.port == CNF_GetAcquisitionPort() ||
+ ip_saddr.port == CNF_GetPtpPort());
if (!have_helper())
return bind(sock, address, address_len);
QNT_Instance inst;
long seed;
- if (q < 2 || min_k > max_k || min_k < 1 || max_k >= q ||
- repeat < 1 || repeat > MAX_REPEAT || min_step <= 0.0 || large_step_delay < 0)
- assert(0);
+ BRIEF_ASSERT(q >= 2 && min_k <= max_k && min_k >= 1 && max_k < q && repeat >= 1 &&
+ repeat <= MAX_REPEAT && min_step > 0.0 && large_step_delay >= 0);
inst = MallocNew(struct QNT_Instance_Record);
inst->n_quants = (max_k - min_k + 1) * repeat;
{
int i, j, r = inst->repeat;
- if (inst->n_set * r >= inst->n_quants)
- assert(0);
+ BRIEF_ASSERT(inst->n_set * r < inst->n_quants);
/* Keep the initial estimates repeated and ordered */
for (i = inst->n_set; i > 0 && inst->quants[(i - 1) * r].est > value; i--) {
double estimates[MAX_REPEAT];
int i;
- if (k < inst->min_k || (k - inst->min_k) * inst->repeat >= inst->n_quants)
- assert(0);
+ BRIEF_ASSERT(k >= inst->min_k && (k - inst->min_k) * inst->repeat < inst->n_quants);
for (i = 0; i < inst->repeat; i++)
estimates[i] = inst->quants[(k - inst->min_k) * inst->repeat + i].est;
#include "memory.h"
#include "siv.h"
+#include "util.h"
struct SIV_Instance_Record {
SIV_Algorithm algorithm;
int
SIV_GetTagLength(SIV_Instance instance)
{
- if (instance->tag_length < 1 || instance->tag_length > SIV_MAX_TAG_LENGTH)
- assert(0);
+ BRIEF_ASSERT(instance->tag_length >= 1 && instance->tag_length <= SIV_MAX_TAG_LENGTH);
return instance->tag_length;
}
n = ARR_GetSize(recv_headers);
n = MIN(n, max_messages);
- if (n < 1 || n > MAX_RECV_MESSAGES ||
- n > ARR_GetSize(recv_messages) || n > ARR_GetSize(recv_sck_messages))
- assert(0);
+ BRIEF_ASSERT(n >= 1 && n <= MAX_RECV_MESSAGES &&
+ n <= ARR_GetSize(recv_messages) && n <= ARR_GetSize(recv_sck_messages));
recv_flags = get_recv_flags(flags);
last_updated_inst = NULL;
assert(initialised);
- if (instance->index < 0 || instance->index >= n_sources ||
- instance != sources[instance->index])
- assert(0);
+ BRIEF_ASSERT(instance->index >= 0 && instance->index < n_sources &&
+ instance == sources[instance->index]);
SST_DeleteInstance(instance->stats);
dead_index = instance->index;
{
set_source_status(inst, status);
- if (status < SRC_OK || status >= sizeof (inst->reported_status))
- assert(0);
+ BRIEF_ASSERT(status >= SRC_OK && status < sizeof (inst->reported_status));
if (!inst->reported_status[status]) {
switch (status) {
#define SQUARE(x) ((x) * (x))
+/* Macro to make an assertion with the text of a long argument replaced
+ with "0" to avoid bloating the compiled binary */
+#ifdef NDEBUG
+#define BRIEF_ASSERT(a)
+#else
+#define BRIEF_ASSERT(a) if (!(a)) assert(0)
+#endif
+
#endif /* GOT_UTIL_H */