crypto/x509v3/v3_asid.c:436: error: NULL_DEREFERENCE
  pointer `a_min` last assigned on line 427 could be null and is dereferenced by call to `ASN1_INTEGER_cmp()` at line 436, column 9.
Showing all 71 steps of the trace


crypto/x509v3/v3_asid.c:393:1: start of procedure ASIdentifierChoice_canonize()
391.    * Whack an ASIdentifierChoice into canonical form.
392.    */
393. > static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice)
394.   {
395.       ASN1_INTEGER *a_max_plus_one = NULL;

crypto/x509v3/v3_asid.c:395:5: 
393.   static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice)
394.   {
395. >     ASN1_INTEGER *a_max_plus_one = NULL;
396.       BIGNUM *bn = NULL;
397.       int i, ret = 0;

crypto/x509v3/v3_asid.c:396:5: 
394.   {
395.       ASN1_INTEGER *a_max_plus_one = NULL;
396. >     BIGNUM *bn = NULL;
397.       int i, ret = 0;
398.   

crypto/x509v3/v3_asid.c:397:5: 
395.       ASN1_INTEGER *a_max_plus_one = NULL;
396.       BIGNUM *bn = NULL;
397. >     int i, ret = 0;
398.   
399.       /*

crypto/x509v3/v3_asid.c:402:9: Taking false branch
400.        * Nothing to do for empty element or inheritance.
401.        */
402.       if (choice == NULL || choice->type == ASIdentifierChoice_inherit)
               ^
403.           return 1;
404.   

crypto/x509v3/v3_asid.c:402:27: Taking false branch
400.        * Nothing to do for empty element or inheritance.
401.        */
402.       if (choice == NULL || choice->type == ASIdentifierChoice_inherit)
                                 ^
403.           return 1;
404.   

crypto/x509v3/v3_asid.c:408:9: Taking false branch
406.        * If not a list, or if empty list, it's broken.
407.        */
408.       if (choice->type != ASIdentifierChoice_asIdsOrRanges ||
               ^
409.           sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0) {
410.           X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,

crypto/x509v3/v3_asid.c:409:9: Condition is true
407.        */
408.       if (choice->type != ASIdentifierChoice_asIdsOrRanges ||
409.           sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0) {
               ^
410.           X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
411.                     X509V3_R_EXTENSION_VALUE_ERROR);

crypto/stack/stack.c:319:1: start of procedure sk_num()
  317.   }
  318.   
  319. > int sk_num(const _STACK *st)
  320.   {
  321.       if (st == NULL)

crypto/stack/stack.c:321:9: Taking false branch
  319.   int sk_num(const _STACK *st)
  320.   {
  321.       if (st == NULL)
                 ^
  322.           return -1;
  323.       return st->num;

crypto/stack/stack.c:323:5: 
  321.       if (st == NULL)
  322.           return -1;
  323. >     return st->num;
  324.   }
  325.   

crypto/stack/stack.c:324:1: return from a call to sk_num
  322.           return -1;
  323.       return st->num;
  324. > }
  325.   
  326.   void *sk_value(const _STACK *st, int i)

crypto/x509v3/v3_asid.c:409:9: Taking false branch
407.        */
408.       if (choice->type != ASIdentifierChoice_asIdsOrRanges ||
409.           sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0) {
               ^
410.           X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
411.                     X509V3_R_EXTENSION_VALUE_ERROR);

crypto/x509v3/v3_asid.c:418:5: Condition is true
416.        * We have a non-empty list.  Sort it.
417.        */
418.       sk_ASIdOrRange_sort(choice->u.asIdsOrRanges);
           ^
419.   
420.       /*

crypto/stack/stack.c:340:1: start of procedure sk_sort()
  338.   }
  339.   
  340. > void sk_sort(_STACK *st)
  341.   {
  342.       if (st && !st->sorted) {

crypto/stack/stack.c:342:9: Taking true branch
  340.   void sk_sort(_STACK *st)
  341.   {
  342.       if (st && !st->sorted) {
                 ^
  343.           int (*comp_func) (const void *, const void *);
  344.   

crypto/stack/stack.c:342:16: Taking true branch
  340.   void sk_sort(_STACK *st)
  341.   {
  342.       if (st && !st->sorted) {
                        ^
  343.           int (*comp_func) (const void *, const void *);
  344.   

crypto/stack/stack.c:352:9: 
  350.            * "now").
  351.            */
  352. >         comp_func = (int (*)(const void *, const void *))(st->comp);
  353.           qsort(st->data, st->num, sizeof(char *), comp_func);
  354.           st->sorted = 1;

crypto/stack/stack.c:353:9: 
  351.            */
  352.           comp_func = (int (*)(const void *, const void *))(st->comp);
  353. >         qsort(st->data, st->num, sizeof(char *), comp_func);
  354.           st->sorted = 1;
  355.       }

crypto/stack/stack.c:354:9: 
  352.           comp_func = (int (*)(const void *, const void *))(st->comp);
  353.           qsort(st->data, st->num, sizeof(char *), comp_func);
  354. >         st->sorted = 1;
  355.       }
  356.   }

crypto/stack/stack.c:342:5: 
  340.   void sk_sort(_STACK *st)
  341.   {
  342. >     if (st && !st->sorted) {
  343.           int (*comp_func) (const void *, const void *);
  344.   

crypto/stack/stack.c:356:1: return from a call to sk_sort
  354.           st->sorted = 1;
  355.       }
  356. > }
  357.   
  358.   int sk_is_sorted(const _STACK *st)

crypto/x509v3/v3_asid.c:424:10: 
422.        * former and fixing the latter.
423.        */
424. >     for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
425.           ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
426.           ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);

crypto/x509v3/v3_asid.c:424:21: Condition is true
422.        * former and fixing the latter.
423.        */
424.       for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
                           ^
425.           ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
426.           ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);

crypto/x509v3/v3_asid.c:424:17: 
422.        * former and fixing the latter.
423.        */
424. >     for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
425.           ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
426.           ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);

crypto/stack/stack.c:319:1: start of procedure sk_num()
  317.   }
  318.   
  319. > int sk_num(const _STACK *st)
  320.   {
  321.       if (st == NULL)

crypto/stack/stack.c:321:9: Taking false branch
  319.   int sk_num(const _STACK *st)
  320.   {
  321.       if (st == NULL)
                 ^
  322.           return -1;
  323.       return st->num;

crypto/stack/stack.c:323:5: 
  321.       if (st == NULL)
  322.           return -1;
  323. >     return st->num;
  324.   }
  325.   

crypto/stack/stack.c:324:1: return from a call to sk_num
  322.           return -1;
  323.       return st->num;
  324. > }
  325.   
  326.   void *sk_value(const _STACK *st, int i)

crypto/x509v3/v3_asid.c:424:17: Loop condition is true. Entering loop body
422.        * former and fixing the latter.
423.        */
424.       for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
                       ^
425.           ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
426.           ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);

crypto/x509v3/v3_asid.c:425:26: Condition is true
423.        */
424.       for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
425.           ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
                                ^
426.           ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);
427.           ASN1_INTEGER *a_min = NULL, *a_max = NULL, *b_min = NULL, *b_max =

crypto/x509v3/v3_asid.c:425:9: 
423.        */
424.       for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
425. >         ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
426.           ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);
427.           ASN1_INTEGER *a_min = NULL, *a_max = NULL, *b_min = NULL, *b_max =

crypto/stack/stack.c:326:1: start of procedure sk_value()
  324.   }
  325.   
  326. > void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))

crypto/stack/stack.c:328:10: Taking false branch
  326.   void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))
                  ^
  329.           return NULL;
  330.       return st->data[i];

crypto/stack/stack.c:328:17: Taking false branch
  326.   void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))
                         ^
  329.           return NULL;
  330.       return st->data[i];

crypto/stack/stack.c:328:28: Taking false branch
  326.   void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))
                                    ^
  329.           return NULL;
  330.       return st->data[i];

crypto/stack/stack.c:330:5: 
  328.       if (!st || (i < 0) || (i >= st->num))
  329.           return NULL;
  330. >     return st->data[i];
  331.   }
  332.   

crypto/stack/stack.c:331:1: return from a call to sk_value
  329.           return NULL;
  330.       return st->data[i];
  331. > }
  332.   
  333.   void *sk_set(_STACK *st, int i, void *value)

crypto/x509v3/v3_asid.c:426:26: Condition is true
424.       for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
425.           ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
426.           ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);
                                ^
427.           ASN1_INTEGER *a_min = NULL, *a_max = NULL, *b_min = NULL, *b_max =
428.               NULL;

crypto/x509v3/v3_asid.c:426:9: 
424.       for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
425.           ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
426. >         ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);
427.           ASN1_INTEGER *a_min = NULL, *a_max = NULL, *b_min = NULL, *b_max =
428.               NULL;

crypto/stack/stack.c:326:1: start of procedure sk_value()
  324.   }
  325.   
  326. > void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))

crypto/stack/stack.c:328:10: Taking false branch
  326.   void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))
                  ^
  329.           return NULL;
  330.       return st->data[i];

crypto/stack/stack.c:328:17: Taking false branch
  326.   void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))
                         ^
  329.           return NULL;
  330.       return st->data[i];

crypto/stack/stack.c:328:28: Taking false branch
  326.   void *sk_value(const _STACK *st, int i)
  327.   {
  328.       if (!st || (i < 0) || (i >= st->num))
                                    ^
  329.           return NULL;
  330.       return st->data[i];

crypto/stack/stack.c:330:5: 
  328.       if (!st || (i < 0) || (i >= st->num))
  329.           return NULL;
  330. >     return st->data[i];
  331.   }
  332.   

crypto/stack/stack.c:331:1: return from a call to sk_value
  329.           return NULL;
  330.       return st->data[i];
  331. > }
  332.   
  333.   void *sk_set(_STACK *st, int i, void *value)

crypto/x509v3/v3_asid.c:427:9: 
425.           ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
426.           ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);
427. >         ASN1_INTEGER *a_min = NULL, *a_max = NULL, *b_min = NULL, *b_max =
428.               NULL;
429.   

crypto/x509v3/v3_asid.c:430:9: 
428.               NULL;
429.   
430. >         extract_min_max(a, &a_min, &a_max);
431.           extract_min_max(b, &b_min, &b_max);
432.   

crypto/x509v3/v3_asid.c:280:1: start of procedure extract_min_max()
  278.    * Extract min and max values from an ASIdOrRange.
  279.    */
  280. > static void extract_min_max(ASIdOrRange *aor,
  281.                               ASN1_INTEGER **min, ASN1_INTEGER **max)
  282.   {

crypto/x509v3/v3_asid.c:283:5: Condition is true
  281.                               ASN1_INTEGER **min, ASN1_INTEGER **max)
  282.   {
  283.       OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
             ^
  284.       switch (aor->type) {
  285.       case ASIdOrRange_id:

crypto/x509v3/v3_asid.c:283:5: Condition is true
  281.                               ASN1_INTEGER **min, ASN1_INTEGER **max)
  282.   {
  283.       OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
             ^
  284.       switch (aor->type) {
  285.       case ASIdOrRange_id:

crypto/x509v3/v3_asid.c:283:5: Condition is true
  281.                               ASN1_INTEGER **min, ASN1_INTEGER **max)
  282.   {
  283.       OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
             ^
  284.       switch (aor->type) {
  285.       case ASIdOrRange_id:

crypto/x509v3/v3_asid.c:284:5: 
  282.   {
  283.       OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
  284. >     switch (aor->type) {
  285.       case ASIdOrRange_id:
  286.           *min = aor->u.id;

crypto/x509v3/v3_asid.c:285:5: Switch condition is false. Skipping switch case
  283.       OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
  284.       switch (aor->type) {
  285.       case ASIdOrRange_id:
             ^
  286.           *min = aor->u.id;
  287.           *max = aor->u.id;

crypto/x509v3/v3_asid.c:289:5: Switch condition is false. Skipping switch case
  287.           *max = aor->u.id;
  288.           return;
  289.       case ASIdOrRange_range:
             ^
  290.           *min = aor->u.range->min;
  291.           *max = aor->u.range->max;

crypto/x509v3/v3_asid.c:294:1: return from a call to extract_min_max
  292.           return;
  293.       }
  294. > }
  295.   
  296.   /*

crypto/x509v3/v3_asid.c:431:9: 
429.   
430.           extract_min_max(a, &a_min, &a_max);
431. >         extract_min_max(b, &b_min, &b_max);
432.   
433.           /*

crypto/x509v3/v3_asid.c:280:1: start of procedure extract_min_max()
  278.    * Extract min and max values from an ASIdOrRange.
  279.    */
  280. > static void extract_min_max(ASIdOrRange *aor,
  281.                               ASN1_INTEGER **min, ASN1_INTEGER **max)
  282.   {

crypto/x509v3/v3_asid.c:283:5: Condition is true
  281.                               ASN1_INTEGER **min, ASN1_INTEGER **max)
  282.   {
  283.       OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
             ^
  284.       switch (aor->type) {
  285.       case ASIdOrRange_id:

crypto/x509v3/v3_asid.c:283:5: Condition is true
  281.                               ASN1_INTEGER **min, ASN1_INTEGER **max)
  282.   {
  283.       OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
             ^
  284.       switch (aor->type) {
  285.       case ASIdOrRange_id:

crypto/x509v3/v3_asid.c:283:5: Condition is true
  281.                               ASN1_INTEGER **min, ASN1_INTEGER **max)
  282.   {
  283.       OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
             ^
  284.       switch (aor->type) {
  285.       case ASIdOrRange_id:

crypto/x509v3/v3_asid.c:284:5: 
  282.   {
  283.       OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
  284. >     switch (aor->type) {
  285.       case ASIdOrRange_id:
  286.           *min = aor->u.id;

crypto/x509v3/v3_asid.c:285:5: Switch condition is false. Skipping switch case
  283.       OPENSSL_assert(aor != NULL && min != NULL && max != NULL);
  284.       switch (aor->type) {
  285.       case ASIdOrRange_id:
             ^
  286.           *min = aor->u.id;
  287.           *max = aor->u.id;

crypto/x509v3/v3_asid.c:289:5: Switch condition is true. Entering switch case
  287.           *max = aor->u.id;
  288.           return;
  289.       case ASIdOrRange_range:
             ^
  290.           *min = aor->u.range->min;
  291.           *max = aor->u.range->max;

crypto/x509v3/v3_asid.c:290:9: 
  288.           return;
  289.       case ASIdOrRange_range:
  290. >         *min = aor->u.range->min;
  291.           *max = aor->u.range->max;
  292.           return;

crypto/x509v3/v3_asid.c:291:9: 
  289.       case ASIdOrRange_range:
  290.           *min = aor->u.range->min;
  291. >         *max = aor->u.range->max;
  292.           return;
  293.       }

crypto/x509v3/v3_asid.c:292:9: 
  290.           *min = aor->u.range->min;
  291.           *max = aor->u.range->max;
  292. >         return;
  293.       }
  294.   }

crypto/x509v3/v3_asid.c:294:1: return from a call to extract_min_max
  292.           return;
  293.       }
  294. > }
  295.   
  296.   /*

crypto/x509v3/v3_asid.c:436:9: 
434.            * Make sure we're properly sorted (paranoia).
435.            */
436. >         OPENSSL_assert(ASN1_INTEGER_cmp(a_min, b_min) <= 0);
437.   
438.           /*

crypto/asn1/a_int.c:69:1: start of procedure ASN1_INTEGER_cmp()
  67.   }
  68.   
  69. > int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)
  70.   {
  71.       int neg, ret;

crypto/asn1/a_int.c:73:5: 
  71.       int neg, ret;
  72.       /* Compare signs */
  73. >     neg = x->type & V_ASN1_NEG;
  74.       if (neg != (y->type & V_ASN1_NEG)) {
  75.           if (neg)

static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice)
{
    ASN1_INTEGER *a_max_plus_one = NULL;
    BIGNUM *bn = NULL;
    int i, ret = 0;
    if (choice == NULL || choice->type == ASIdentifierChoice_inherit)
        return 1;
    if (choice->type != ASIdentifierChoice_asIdsOrRanges ||
        sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0) {
        X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
                  X509V3_R_EXTENSION_VALUE_ERROR);
        return 0;
    }
    sk_ASIdOrRange_sort(choice->u.asIdsOrRanges);
    for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
        ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
        ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);
        ASN1_INTEGER *a_min = NULL, *a_max = NULL, *b_min = NULL, *b_max =
            NULL;
        extract_min_max(a, &a_min, &a_max);
        extract_min_max(b, &b_min, &b_max);
        OPENSSL_assert(ASN1_INTEGER_cmp(a_min, b_min) <= 0);
        if (ASN1_INTEGER_cmp(a_min, a_max) > 0 ||
            ASN1_INTEGER_cmp(b_min, b_max) > 0)
            goto done;
        if (ASN1_INTEGER_cmp(a_max, b_min) >= 0) {
            X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
                      X509V3_R_EXTENSION_VALUE_ERROR);
            goto done;
        }
        if ((bn == NULL && (bn = BN_new()) == NULL) ||
            ASN1_INTEGER_to_BN(a_max, bn) == NULL ||
            !BN_add_word(bn, 1) ||
            (a_max_plus_one =
             BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) {
            X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
                      ERR_R_MALLOC_FAILURE);
            goto done;
        }
        if (ASN1_INTEGER_cmp(a_max_plus_one, b_min) == 0) {
            ASRange *r;
            switch (a->type) {
            case ASIdOrRange_id:
                if ((r = OPENSSL_malloc(sizeof(ASRange))) == NULL) {
                    X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
                              ERR_R_MALLOC_FAILURE);
                    goto done;
                }
                r->min = a_min;
                r->max = b_max;
                a->type = ASIdOrRange_range;
                a->u.range = r;
                break;
            case ASIdOrRange_range:
                ASN1_INTEGER_free(a->u.range->max);
                a->u.range->max = b_max;
                break;
            }
            switch (b->type) {
            case ASIdOrRange_id:
                b->u.id = NULL;
                break;
            case ASIdOrRange_range:
                b->u.range->max = NULL;
                break;
            }
            ASIdOrRange_free(b);
            (void)sk_ASIdOrRange_delete(choice->u.asIdsOrRanges, i + 1);
            i--;
            continue;
        }
    }
    i = sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1;
    {
        ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
        ASN1_INTEGER *a_min, *a_max;
        if (a != NULL && a->type == ASIdOrRange_range) {
            extract_min_max(a, &a_min, &a_max);
            if (ASN1_INTEGER_cmp(a_min, a_max) > 0)
                goto done;
        }
    }
    OPENSSL_assert(ASIdentifierChoice_is_canonical(choice));
    ret = 1;
 done:
    ASN1_INTEGER_free(a_max_plus_one);
    BN_free(bn);
    return ret;
}
['static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice)\n{\n    ASN1_INTEGER *a_max_plus_one = NULL;\n    BIGNUM *bn = NULL;\n    int i, ret = 0;\n    if (choice == NULL || choice->type == ASIdentifierChoice_inherit)\n        return 1;\n    if (choice->type != ASIdentifierChoice_asIdsOrRanges ||\n        sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0) {\n        X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,\n                  X509V3_R_EXTENSION_VALUE_ERROR);\n        return 0;\n    }\n    sk_ASIdOrRange_sort(choice->u.asIdsOrRanges);\n    for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {\n        ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);\n        ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);\n        ASN1_INTEGER *a_min = NULL, *a_max = NULL, *b_min = NULL, *b_max =\n            NULL;\n        extract_min_max(a, &a_min, &a_max);\n        extract_min_max(b, &b_min, &b_max);\n        OPENSSL_assert(ASN1_INTEGER_cmp(a_min, b_min) <= 0);\n        if (ASN1_INTEGER_cmp(a_min, a_max) > 0 ||\n            ASN1_INTEGER_cmp(b_min, b_max) > 0)\n            goto done;\n        if (ASN1_INTEGER_cmp(a_max, b_min) >= 0) {\n            X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,\n                      X509V3_R_EXTENSION_VALUE_ERROR);\n            goto done;\n        }\n        if ((bn == NULL && (bn = BN_new()) == NULL) ||\n            ASN1_INTEGER_to_BN(a_max, bn) == NULL ||\n            !BN_add_word(bn, 1) ||\n            (a_max_plus_one =\n             BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) {\n            X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,\n                      ERR_R_MALLOC_FAILURE);\n            goto done;\n        }\n        if (ASN1_INTEGER_cmp(a_max_plus_one, b_min) == 0) {\n            ASRange *r;\n            switch (a->type) {\n            case ASIdOrRange_id:\n                if ((r = OPENSSL_malloc(sizeof(ASRange))) == NULL) {\n                    X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,\n                              ERR_R_MALLOC_FAILURE);\n                    goto done;\n                }\n                r->min = a_min;\n                r->max = b_max;\n                a->type = ASIdOrRange_range;\n                a->u.range = r;\n                break;\n            case ASIdOrRange_range:\n                ASN1_INTEGER_free(a->u.range->max);\n                a->u.range->max = b_max;\n                break;\n            }\n            switch (b->type) {\n            case ASIdOrRange_id:\n                b->u.id = NULL;\n                break;\n            case ASIdOrRange_range:\n                b->u.range->max = NULL;\n                break;\n            }\n            ASIdOrRange_free(b);\n            (void)sk_ASIdOrRange_delete(choice->u.asIdsOrRanges, i + 1);\n            i--;\n            continue;\n        }\n    }\n    i = sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1;\n    {\n        ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);\n        ASN1_INTEGER *a_min, *a_max;\n        if (a != NULL && a->type == ASIdOrRange_range) {\n            extract_min_max(a, &a_min, &a_max);\n            if (ASN1_INTEGER_cmp(a_min, a_max) > 0)\n                goto done;\n        }\n    }\n    OPENSSL_assert(ASIdentifierChoice_is_canonical(choice));\n    ret = 1;\n done:\n    ASN1_INTEGER_free(a_max_plus_one);\n    BN_free(bn);\n    return ret;\n}', 'int sk_num(const _STACK *st)\n{\n    if (st == NULL)\n        return -1;\n    return st->num;\n}', 'void sk_sort(_STACK *st)\n{\n    if (st && !st->sorted) {\n        int (*comp_func) (const void *, const void *);\n        comp_func = (int (*)(const void *, const void *))(st->comp);\n        qsort(st->data, st->num, sizeof(char *), comp_func);\n        st->sorted = 1;\n    }\n}', 'void *sk_value(const _STACK *st, int i)\n{\n    if (!st || (i < 0) || (i >= st->num))\n        return NULL;\n    return st->data[i];\n}', 'static void extract_min_max(ASIdOrRange *aor,\n                            ASN1_INTEGER **min, ASN1_INTEGER **max)\n{\n    OPENSSL_assert(aor != NULL && min != NULL && max != NULL);\n    switch (aor->type) {\n    case ASIdOrRange_id:\n        *min = aor->u.id;\n        *max = aor->u.id;\n        return;\n    case ASIdOrRange_range:\n        *min = aor->u.range->min;\n        *max = aor->u.range->max;\n        return;\n    }\n}', 'int ASN1_INTEGER_cmp(const ASN1_INTEGER *x, const ASN1_INTEGER *y)\n{\n    int neg, ret;\n    neg = x->type & V_ASN1_NEG;\n    if (neg != (y->type & V_ASN1_NEG)) {\n        if (neg)\n            return -1;\n        else\n            return 1;\n    }\n    ret = ASN1_STRING_cmp(x, y);\n    if (neg)\n        return -ret;\n    else\n        return ret;\n}']