Hi all,
This is a second post of my patches for pqueue. I've also fixed
a few things based on comments I received.
These patches have only been build tested so far. No functional
change is intended. It is a simplification of the existing code.
ok?
Index: pqueue.c
===================================================================
RCS file: /cvs/src/lib/libssl/src/crypto/pqueue/pqueue.c,v
retrieving revision 1.4
diff -u -p -r1.4 pqueue.c
--- pqueue.c 27 Apr 2014 20:20:59 -0000 1.4
+++ pqueue.c 29 Apr 2014 09:54:20 -0000
@@ -69,8 +69,9 @@ typedef struct _pqueue {
pitem *
pitem_new(unsigned char *prio64be, void *data)
{
- pitem *item = (pitem *)malloc(sizeof(pitem));
+ pitem *item;
+ item = malloc(sizeof(pitem));
if (item == NULL)
return NULL;
@@ -85,30 +86,18 @@ pitem_new(unsigned char *prio64be, void
void
pitem_free(pitem *item)
{
- if (item == NULL)
- return;
-
free(item);
}
pqueue_s *
pqueue_new(void)
{
- pqueue_s *pq = (pqueue_s *)malloc(sizeof(pqueue_s));
-
- if (pq == NULL)
- return NULL;
-
- memset(pq, 0x00, sizeof(pqueue_s));
- return pq;
+ return calloc(1, sizeof(pqueue_s));
}
void
pqueue_free(pqueue_s *pq)
{
- if (pq == NULL)
- return;
-
free(pq);
}
Index: pqueue.c
===================================================================
RCS file: /cvs/src/lib/libssl/src/crypto/pqueue/pqueue.c,v
retrieving revision 1.4
diff -u -p -r1.4 pqueue.c
--- pqueue.c 27 Apr 2014 20:20:59 -0000 1.4
+++ pqueue.c 29 Apr 2014 10:47:54 -0000
@@ -168,33 +168,12 @@ pitem *
pqueue_find(pqueue_s *pq, unsigned char *prio64be)
{
pitem *next;
- pitem *found = NULL;
- if (pq->items == NULL)
- return NULL;
+ for (next = pq->items; next != NULL; next = next->next)
+ if (memcmp(next->priority, prio64be, 8) == 0)
+ return next;
- for (next = pq->items; next->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)
- return NULL;
-
-#if 0 /* find works in peek mode */
- if (prev == NULL)
- pq->items = next->next;
- else
- prev->next = next->next;
-#endif
-
- return found;
+ return NULL;
}
void