diff options
author | miod <> | 2014-05-06 20:32:11 +0000 |
---|---|---|
committer | miod <> | 2014-05-06 20:32:11 +0000 |
commit | ba38ba8b09f85df1d5bad87c6be04deeaa05cca9 (patch) | |
tree | 564e602e76e9cbd24402a905111568f3cba0e62a | |
parent | 7bb05eec196fcd9eb44b7d63832486843a5e6c0d (diff) | |
download | openbsd-ba38ba8b09f85df1d5bad87c6be04deeaa05cca9.tar.gz openbsd-ba38ba8b09f85df1d5bad87c6be04deeaa05cca9.tar.bz2 openbsd-ba38ba8b09f85df1d5bad87c6be04deeaa05cca9.zip |
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!
-rw-r--r-- | src/lib/libcrypto/pqueue/pqueue.c | 18 | ||||
-rw-r--r-- | src/lib/libssl/src/crypto/pqueue/pqueue.c | 18 |
2 files changed, 8 insertions, 28 deletions
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) | |||
126 | curr = next, next = next->next) { | 126 | curr = next, next = next->next) { |
127 | /* we can compare 64-bit value in big-endian encoding | 127 | /* we can compare 64-bit value in big-endian encoding |
128 | * with memcmp:-) */ | 128 | * with memcmp:-) */ |
129 | int cmp = memcmp(next->priority, item->priority, 8); | 129 | int cmp = memcmp(next->priority, item->priority, |
130 | sizeof(item->priority)); | ||
130 | if (cmp > 0) /* next > item */ | 131 | if (cmp > 0) /* next > item */ |
131 | { | 132 | { |
132 | item->next = next; | 133 | item->next = next; |
@@ -173,27 +174,16 @@ pqueue_find(pqueue_s *pq, unsigned char *prio64be) | |||
173 | if (pq->items == NULL) | 174 | if (pq->items == NULL) |
174 | return NULL; | 175 | return NULL; |
175 | 176 | ||
176 | for (next = pq->items; next->next != NULL; next = next->next) { | 177 | for (next = pq->items; next != NULL; next = next->next) { |
177 | if (memcmp(next->priority, prio64be, 8) == 0) { | 178 | if (memcmp(next->priority, prio64be, 8) == 0) { |
178 | found = next; | 179 | found = next; |
179 | break; | 180 | break; |
180 | } | 181 | } |
181 | } | 182 | } |
182 | 183 | ||
183 | /* check the one last node */ | 184 | if (!found) |
184 | if (memcmp(next->priority, prio64be, 8) ==0) | ||
185 | found = next; | ||
186 | |||
187 | if (! found) | ||
188 | return NULL; | 185 | return NULL; |
189 | 186 | ||
190 | #if 0 /* find works in peek mode */ | ||
191 | if (prev == NULL) | ||
192 | pq->items = next->next; | ||
193 | else | ||
194 | prev->next = next->next; | ||
195 | #endif | ||
196 | |||
197 | return found; | 187 | return found; |
198 | } | 188 | } |
199 | 189 | ||
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) | |||
126 | curr = next, next = next->next) { | 126 | curr = next, next = next->next) { |
127 | /* we can compare 64-bit value in big-endian encoding | 127 | /* we can compare 64-bit value in big-endian encoding |
128 | * with memcmp:-) */ | 128 | * with memcmp:-) */ |
129 | int cmp = memcmp(next->priority, item->priority, 8); | 129 | int cmp = memcmp(next->priority, item->priority, |
130 | sizeof(item->priority)); | ||
130 | if (cmp > 0) /* next > item */ | 131 | if (cmp > 0) /* next > item */ |
131 | { | 132 | { |
132 | item->next = next; | 133 | item->next = next; |
@@ -173,27 +174,16 @@ pqueue_find(pqueue_s *pq, unsigned char *prio64be) | |||
173 | if (pq->items == NULL) | 174 | if (pq->items == NULL) |
174 | return NULL; | 175 | return NULL; |
175 | 176 | ||
176 | for (next = pq->items; next->next != NULL; next = next->next) { | 177 | for (next = pq->items; next != NULL; next = next->next) { |
177 | if (memcmp(next->priority, prio64be, 8) == 0) { | 178 | if (memcmp(next->priority, prio64be, 8) == 0) { |
178 | found = next; | 179 | found = next; |
179 | break; | 180 | break; |
180 | } | 181 | } |
181 | } | 182 | } |
182 | 183 | ||
183 | /* check the one last node */ | 184 | if (!found) |
184 | if (memcmp(next->priority, prio64be, 8) ==0) | ||
185 | found = next; | ||
186 | |||
187 | if (! found) | ||
188 | return NULL; | 185 | return NULL; |
189 | 186 | ||
190 | #if 0 /* find works in peek mode */ | ||
191 | if (prev == NULL) | ||
192 | pq->items = next->next; | ||
193 | else | ||
194 | prev->next = next->next; | ||
195 | #endif | ||
196 | |||
197 | return found; | 187 | return found; |
198 | } | 188 | } |
199 | 189 | ||