aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil/nstime.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2014-05-23 16:40:56 -0700
committerGuy Harris <guy@alum.mit.edu>2014-05-23 23:41:21 +0000
commitd470a468a63a081688ddc2c6d125e4e2edafecfc (patch)
treefade7330c732842355b5d957a2fe98e868bf3a49 /wsutil/nstime.c
parent9e2db542a28377d106c4dc99fff15499a4e26fd7 (diff)
More handling of missing time stamps.
Make nstime_cmp() handle "unset" time stamps (they're equal to other "unset" time stamps, and less than all other time stamps), use it in reordercap, and "unset" the time stamp if it's absent. Also, nstime_cmp() does not modify its argument, so make it const. Change-Id: I016dab5fefaf4696e78cbd8c6dd3395808e54369 Reviewed-on: https://code.wireshark.org/review/1769 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wsutil/nstime.c')
-rw-r--r--wsutil/nstime.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/wsutil/nstime.c b/wsutil/nstime.c
index c53e67fffd..bb4ba5e6f6 100644
--- a/wsutil/nstime.c
+++ b/wsutil/nstime.c
@@ -59,7 +59,7 @@ void nstime_set_unset(nstime_t *nstime)
}
/* is the given nstime_t currently (0,maxint)? */
-gboolean nstime_is_unset(nstime_t *nstime)
+gboolean nstime_is_unset(const nstime_t *nstime)
{
if(nstime->secs == 0 && nstime->nsecs == G_MAXINT) {
return TRUE;
@@ -148,6 +148,17 @@ void nstime_sum(nstime_t *sum, const nstime_t *a, const nstime_t *b)
int nstime_cmp (const nstime_t *a, const nstime_t *b )
{
+ if (G_UNLIKELY(nstime_is_unset(a))) {
+ if (G_UNLIKELY(nstime_is_unset(b))) {
+ return 0; /* "no time stamp" is "equal" to "no time stamp" */
+ } else {
+ return -1; /* and is less than all time stamps */
+ }
+ } else {
+ if (G_UNLIKELY(nstime_is_unset(b))) {
+ return 1;
+ }
+ }
if (a->secs == b->secs) {
return a->nsecs - b->nsecs;
} else {