Add macros to initialize nstime_t values and use them.

This allows code to initialize them without having to know the details
of the structure; the initializes should, and will, be changed if the
members of the structure are changed.

Change-Id: I93e6ebfcde9ceca17df696fcba4e8410c5afb175
Reviewed-on: https://code.wireshark.org/review/28501
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2018-06-27 20:39:15 -07:00
parent c8518753c8
commit 8304f69fd7
8 changed files with 33 additions and 13 deletions

View File

@ -159,8 +159,8 @@ static int out_file_type_subtype = WTAP_FILE_TYPE_SUBTYPE
#endif
static int out_frame_type = -2; /* Leave frame type alone */
static int verbose = 0; /* Not so verbose */
static struct time_adjustment time_adj = {{0, 0}, 0}; /* no adjustment */
static nstime_t relative_time_window = {0, 0}; /* de-dup time window */
static struct time_adjustment time_adj = {NSTIME_INIT_ZERO, 0}; /* no adjustment */
static nstime_t relative_time_window = NSTIME_INIT_ZERO; /* de-dup time window */
static double err_prob = 0.0;
static time_t starttime = 0;
static time_t stoptime = 0;
@ -170,8 +170,8 @@ static gboolean dup_detect = FALSE;
static gboolean dup_detect_by_time = FALSE;
static int do_strict_time_adjustment = FALSE;
static struct time_adjustment strict_time_adj = {{0, 0}, 0}; /* strict time adjustment */
static nstime_t previous_time = {0, 0}; /* previous time */
static struct time_adjustment strict_time_adj = {NSTIME_INIT_ZERO, 0}; /* strict time adjustment */
static nstime_t previous_time = NSTIME_INIT_ZERO; /* previous time */
static int find_dct2000_real_data(guint8 *buf);
static void handle_chopping(chop_t chop, wtap_packet_header *out_phdr,

View File

@ -190,7 +190,7 @@ void proto_reg_handoff_collectd (void);
static nstime_t
collectd_time_to_nstime (guint64 t)
{
nstime_t nstime = { 0, 0 };
nstime_t nstime = NSTIME_INIT_ZERO;;
nstime.secs = (time_t) (t / 1073741824);
nstime.nsecs = (int) (((double) (t % 1073741824)) / 1.073741824);

View File

@ -3677,7 +3677,7 @@ dissect_dns_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
gboolean retransmission = FALSE;
const guchar *name;
int name_len;
nstime_t delta = { 0, 0 };
nstime_t delta = NSTIME_INIT_ZERO;
dns_data_offset = offset;

View File

@ -996,7 +996,7 @@ static iax_call_data *iax_new_call( packet_info *pinfo,
{
iax_call_data *call;
guint circuit_id;
static const nstime_t millisecond = {0, 1000000};
static const nstime_t millisecond = NSTIME_INIT_SECS_MSECS(0, 1);
#ifdef DEBUG_HASHING
g_debug("+ new_circuit: Handling NEW packet, frame %u", pinfo->num);

View File

@ -269,7 +269,7 @@ static gboolean rtpproxy_establish_conversation = TRUE;
/* See - https://www.opensips.org/html/docs/modules/1.10.x/rtpproxy.html#id293555 */
/* See - http://www.kamailio.org/docs/modules/4.3.x/modules/rtpproxy.html#idp15794952 */
static guint rtpproxy_timeout = 1000;
static nstime_t rtpproxy_timeout_ns = {1, 0};
static nstime_t rtpproxy_timeout_ns = NSTIME_INIT_ZERO;
void proto_reg_handoff_rtpproxy(void);

View File

@ -1894,7 +1894,7 @@ submit_sm(proto_tree *tree, tvbuff_t *tvb, packet_info *pinfo,
const char *src_str = NULL;
const char *dst_str = NULL;
address save_src, save_dst;
nstime_t zero_time = {0, 0};
nstime_t zero_time = NSTIME_INIT_ZERO;
smpp_handle_string_z(tree, tvb, hf_smpp_service_type, &offset, "(Default)");
smpp_handle_int1(tree, tvb, hf_smpp_source_addr_ton, &offset);
@ -1970,7 +1970,7 @@ replace_sm(proto_tree *tree, tvbuff_t *tvb)
int offset = 0;
guint8 flag;
guint8 length;
nstime_t zero_time = {0, 0};
nstime_t zero_time = NSTIME_INIT_ZERO;
smpp_handle_string(tree, tvb, hf_smpp_message_id, &offset);
smpp_handle_int1(tree, tvb, hf_smpp_source_addr_ton, &offset);
@ -2022,7 +2022,7 @@ submit_multi(proto_tree *tree, tvbuff_t *tvb)
int offset = 0;
guint8 flag;
guint8 length;
nstime_t zero_time = {0, 0};
nstime_t zero_time = NSTIME_INIT_ZERO;
smpp_handle_string_z(tree, tvb, hf_smpp_service_type, &offset, "(Default)");
smpp_handle_int1(tree, tvb, hf_smpp_source_addr_ton, &offset);
@ -2120,7 +2120,7 @@ static void
broadcast_sm(proto_tree *tree, tvbuff_t *tvb)
{
int offset = 0;
nstime_t zero_time = {0, 0};
nstime_t zero_time = NSTIME_INIT_ZERO;
smpp_handle_string_z(tree, tvb, hf_smpp_service_type, &offset, "(Default)");
smpp_handle_int1(tree, tvb, hf_smpp_source_addr_ton, &offset);

View File

@ -245,7 +245,7 @@ merge_read_packet(int in_file_count, merge_in_file_t in_files[],
{
int i;
int ei = -1;
nstime_t tv = { sizeof(time_t) > sizeof(int) ? LONG_MAX : INT_MAX, INT_MAX };
nstime_t tv = NSTIME_INIT_MAX;
wtap_rec *rec;
/*

View File

@ -29,6 +29,26 @@ typedef struct {
int nsecs;
} nstime_t;
/* Macros that expand to nstime_t initializers */
/* Initialize to zero */
#define NSTIME_INIT_ZERO {0, 0}
/* Initialize to a specified number of seconds and nanoseconds */
#define NSTIME_INIT_SECS_NSECS(secs, nsecs) {secs, nsecs}
/* Initialize to a specified number of seconds and microseconds */
#define NSTIME_INIT_SECS_USECS(secs, usecs) {secs, usecs*1000}
/* Initialize to a specified number of seconds and milliseconds */
#define NSTIME_INIT_SECS_MSECS(secs, msecs) {secs, msecs*1000000}
/* Initialize to a specified number of seconds */
#define NSTIME_INIT_SECS(secs) {secs, 0}
/* Initialize to the maxximum possible value */
#define NSTIME_INIT_MAX {sizeof(time_t) > sizeof(int) ? LONG_MAX : INT_MAX, INT_MAX}
/* functions */
/** set the given nstime_t to zero */