[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/3] Make _asn1_ordering_set_of() really sort.
From: |
Kurt Roeckx |
Subject: |
Re: [PATCH 1/3] Make _asn1_ordering_set_of() really sort. |
Date: |
Sat, 26 Apr 2014 18:15:27 +0200 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
So I can't see how the old code really sorted like it's supposed
to. We're probably lacking a test case that checks the result of
the coding is really what we produced. But this seems more likely
to actually produce the expected output.
I should probably do the same for _asn1_ordering_set().
Kurt
On Sat, Apr 26, 2014 at 06:10:30PM +0200, Kurt Roeckx wrote:
> ---
> lib/coding.c | 60
> +++++++++++++++++++++++++++++++++++-------------------------
> 1 file changed, 35 insertions(+), 25 deletions(-)
>
> diff --git a/lib/coding.c b/lib/coding.c
> index 0df3766..6cf3b31 100644
> --- a/lib/coding.c
> +++ b/lib/coding.c
> @@ -844,8 +844,9 @@ _asn1_ordering_set_of (unsigned char *der, int der_len,
> asn1_node node)
> {
> struct vet
> {
> + int start;
> int end;
> - struct vet *next, *prev;
> + struct vet *next;
> };
>
> int counter, len, len2, change;
> @@ -879,8 +880,8 @@ _asn1_ordering_set_of (unsigned char *der, int der_len,
> asn1_node node)
> goto error;
> }
>
> + p_vet->start = counter;
> p_vet->next = NULL;
> - p_vet->prev = last;
> if (first == NULL)
> first = p_vet;
> else
> @@ -915,62 +916,71 @@ _asn1_ordering_set_of (unsigned char *der, int der_len,
> asn1_node node)
> while (p_vet)
> {
> p2_vet = p_vet->next;
> - counter = 0;
> while (p2_vet)
> {
> - if ((p_vet->end - counter) > (p2_vet->end - p_vet->end))
> - max = p_vet->end - counter;
> + len = p_vet->end - p_vet->start;
> + len2 = p2_vet->end - p2_vet->start;
> + if (len > len2)
> + max = len;
> else
> - max = p2_vet->end - p_vet->end;
> + max = len2;
>
> change = -1;
> for (k = 0; k < max; k++)
> - if (der[counter + k] > der[p_vet->end + k])
> + if (der[p_vet->start + k] > der[p2_vet->start + k])
> {
> change = 1;
> break;
> }
> - else if (der[counter + k] < der[p_vet->end + k])
> + else if (der[p_vet->start + k] < der[p2_vet->start + k])
> {
> change = 0;
> break;
> }
>
> - if ((change == -1)
> - && ((p_vet->end - counter) > (p2_vet->end - p_vet->end)))
> + if ((change == -1) && (len > len2))
> change = 1;
>
> if (change == 1)
> {
> /* change position */
> - temp = malloc (p_vet->end - counter);
> + struct vet *temp_vet;
> + int diff;
> + temp = malloc (p2_vet->start - p_vet->start);
> if (temp == NULL)
> {
> err = ASN1_MEM_ALLOC_ERROR;
> goto error;
> }
>
> - memcpy (temp, der + counter, (p_vet->end) - counter);
> - memcpy (der + counter, der + (p_vet->end),
> - (p2_vet->end) - (p_vet->end));
> - memcpy (der + counter + (p2_vet->end) - (p_vet->end), temp,
> - (p_vet->end) - counter);
> + memcpy (temp, der + p_vet->start, p2_vet->start - p_vet->start);
> + memcpy (der + p_vet->start, der + p2_vet->start, len2);
> + memcpy (der + p_vet->start + len2, temp,
> + p2_vet->start - p_vet->start);
> +
> free (temp);
> + temp = NULL;
>
> - p_vet->end = counter + (p2_vet->end - p_vet->end);
> + diff = len - len2;
> + p_vet->end -= diff;
> + for (temp_vet = p_vet->next; temp_vet != p2_vet;
> + temp_vet = temp_vet->next)
> + {
> + len2 = len;
> + len = temp_vet->end - temp_vet->start;
> + temp_vet->start -= diff;
> + diff += len - len2;
> + temp_vet->end -= diff;
> + }
> + p2_vet->start -= diff;
> }
> - counter = p_vet->end;
>
> p2_vet = p2_vet->next;
> - p_vet = p_vet->next;
> }
>
> - if (p_vet != first)
> - p_vet->prev->next = NULL;
> - else
> - first = NULL;
> - free (p_vet);
> - p_vet = first;
> + p_vet = p_vet->next;
> + free (first);
> + first = p_vet;
> }
> return ASN1_SUCCESS;
>
> --
> 1.9.2
>
- [PATCH 1/3] Make _asn1_ordering_set_of() really sort., Kurt Roeckx, 2014/04/26
- [PATCH 2/3] Make asn1_ordering_set_of() return error if it can't find data for one of the entries., Kurt Roeckx, 2014/04/26
- [PATCH 3/3] Check that p is not NULL, Kurt Roeckx, 2014/04/26
- Re: [PATCH 1/3] Make _asn1_ordering_set_of() really sort.,
Kurt Roeckx <=
- Re: [PATCH 1/3] Make _asn1_ordering_set_of() really sort., Kurt Roeckx, 2014/04/26
- Re: [PATCH 1/3] Make _asn1_ordering_set_of() really sort., Nikos Mavrogiannopoulos, 2014/04/27
- Re: [PATCH 1/3] Make _asn1_ordering_set_of() really sort., Kurt Roeckx, 2014/04/27
- Re: [PATCH 1/3] Make _asn1_ordering_set_of() really sort., Nikos Mavrogiannopoulos, 2014/04/27
- Re: [PATCH 1/3] Make _asn1_ordering_set_of() really sort., Kurt Roeckx, 2014/04/27
- Re: [PATCH 1/3] Make _asn1_ordering_set_of() really sort., Nikos Mavrogiannopoulos, 2014/04/27
- Re: [PATCH 1/3] Make _asn1_ordering_set_of() really sort., Kurt Roeckx, 2014/04/27
Re: [PATCH 1/3] Make _asn1_ordering_set_of() really sort., Kurt Roeckx, 2014/04/26