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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

crypto/asn1/a_int.c:77:9: 
  75.       /* Compare signs */
  76.       neg = x->type & V_ASN1_NEG;
  77. >     if (neg != (y->type & V_ASN1_NEG)) {
  78.           if (neg)
  79.               return -1;

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(*r))) == 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(*r))) == 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}']