From ba38ba8b09f85df1d5bad87c6be04deeaa05cca9 Mon Sep 17 00:00:00 2001 From: miod <> Date: Tue, 6 May 2014 20:32:11 +0000 Subject: Assorted cleanups: - replace hardcoded sizes with sizeof() - pqueue_find() apparently used to need to keep track of the previous node when iterating, which causes its logic to be complicated. However, nowadays it only needs to iterate, so replace with a straightforward, much readable logic. - remove #if 0'ed code From ``sin'' from 2f30 dot org on tech@, thanks! --- src/lib/libcrypto/pqueue/pqueue.c | 18 ++++-------------- src/lib/libssl/src/crypto/pqueue/pqueue.c | 18 ++++-------------- 2 files changed, 8 insertions(+), 28 deletions(-) (limited to 'src/lib') diff --git a/src/lib/libcrypto/pqueue/pqueue.c b/src/lib/libcrypto/pqueue/pqueue.c index b8fed503a5..fc68ae19c3 100644 --- a/src/lib/libcrypto/pqueue/pqueue.c +++ b/src/lib/libcrypto/pqueue/pqueue.c @@ -126,7 +126,8 @@ pqueue_insert(pqueue_s *pq, pitem *item) curr = next, next = next->next) { /* we can compare 64-bit value in big-endian encoding * with memcmp:-) */ - int cmp = memcmp(next->priority, item->priority, 8); + int cmp = memcmp(next->priority, item->priority, + sizeof(item->priority)); if (cmp > 0) /* next > item */ { item->next = next; @@ -173,27 +174,16 @@ pqueue_find(pqueue_s *pq, unsigned char *prio64be) if (pq->items == NULL) return NULL; - for (next = pq->items; next->next != NULL; next = next->next) { + for (next = pq->items; next != NULL; next = next->next) { if (memcmp(next->priority, prio64be, 8) == 0) { found = next; break; } } - /* check the one last node */ - if (memcmp(next->priority, prio64be, 8) ==0) - found = next; - - if (! found) + if (!found) return NULL; -#if 0 /* find works in peek mode */ - if (prev == NULL) - pq->items = next->next; - else - prev->next = next->next; -#endif - return found; } diff --git a/src/lib/libssl/src/crypto/pqueue/pqueue.c b/src/lib/libssl/src/crypto/pqueue/pqueue.c index b8fed503a5..fc68ae19c3 100644 --- a/src/lib/libssl/src/crypto/pqueue/pqueue.c +++ b/src/lib/libssl/src/crypto/pqueue/pqueue.c @@ -126,7 +126,8 @@ pqueue_insert(pqueue_s *pq, pitem *item) curr = next, next = next->next) { /* we can compare 64-bit value in big-endian encoding * with memcmp:-) */ - int cmp = memcmp(next->priority, item->priority, 8); + int cmp = memcmp(next->priority, item->priority, + sizeof(item->priority)); if (cmp > 0) /* next > item */ { item->next = next; @@ -173,27 +174,16 @@ pqueue_find(pqueue_s *pq, unsigned char *prio64be) if (pq->items == NULL) return NULL; - for (next = pq->items; next->next != NULL; next = next->next) { + for (next = pq->items; next != NULL; next = next->next) { if (memcmp(next->priority, prio64be, 8) == 0) { found = next; break; } } - /* check the one last node */ - if (memcmp(next->priority, prio64be, 8) ==0) - found = next; - - if (! found) + if (!found) return NULL; -#if 0 /* find works in peek mode */ - if (prev == NULL) - pq->items = next->next; - else - prev->next = next->next; -#endif - return found; } -- cgit v1.2.3-55-g6feb