BOOLEAN_rfill.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Lev Walkin <vlm@lionet.info>.
3  * All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
8 
11  const asn_encoding_constraints_t *constraints,
12  size_t max_length) {
13  asn_random_fill_result_t result_ok = {ARFILL_OK, 1};
14  asn_random_fill_result_t result_failed = {ARFILL_FAILED, 0};
15  asn_random_fill_result_t result_skipped = {ARFILL_SKIPPED, 0};
16  BOOLEAN_t *st = *sptr;
17 
18  if(max_length == 0) return result_skipped;
19 
20  if(st == NULL) {
21  st = (BOOLEAN_t *)(*sptr = CALLOC(1, sizeof(*st)));
22  if(st == NULL) {
23  return result_failed;
24  }
25  }
26 
27 #if !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT)
28  if(!constraints || !constraints->per_constraints)
29  constraints = &td->encoding_constraints;
30  if(constraints->per_constraints) {
31  const asn_per_constraint_t *pc = &constraints->per_constraints->value;
32  if(pc->flags & APC_CONSTRAINED) {
34  return result_ok;
35  }
36  }
37 #else
38  if(!constraints) constraints = &td->encoding_constraints;
39 #endif /* !defined(ASN_DISABLE_UPER_SUPPORT) || !defined(ASN_DISABLE_APER_SUPPORT) */
40 
41  /* Simulate booleans that are sloppily set and biased. */
42  switch(asn_random_between(0, 7)) {
43  case 0:
44  case 1:
45  case 2:
46  *st = 0; break;
47  case 3: *st = -1; break;
48  case 4: *st = 1; break;
49  case 5: *st = INT_MIN; break;
50  case 6: *st = INT_MAX; break;
51  default:
52  *st = asn_random_between(INT_MIN, INT_MAX);
53  break;
54  }
55  return result_ok;
56 }
BOOLEAN.h
asn_per_constraint_s::lower_bound
intmax_t lower_bound
Definition: per_support.h:27
CALLOC
#define CALLOC(nmemb, size)
Definition: asn_internal.h:37
asn_per_constraints_s::value
asn_per_constraint_t value
Definition: per_support.h:31
asn_per_constraint_s
Definition: per_support.h:18
asn_TYPE_descriptor_s
Definition: constr_TYPE.h:224
asn_random_fill_result_s
Definition: asn_random_fill.h:24
asn_random_between
intmax_t asn_random_between(intmax_t min, intmax_t max)
Definition: asn_random_fill.c:38
BOOLEAN_random_fill
asn_random_fill_result_t BOOLEAN_random_fill(const asn_TYPE_descriptor_t *td, void **sptr, const asn_encoding_constraints_t *constraints, size_t max_length)
Definition: BOOLEAN_rfill.c:10
asn_encoding_constraints_s::per_constraints
const struct asn_per_constraints_s * per_constraints
Definition: constr_TYPE.h:213
asn_encoding_constraints_s
Definition: constr_TYPE.h:208
asn_internal.h
BOOLEAN_t
unsigned BOOLEAN_t
Definition: BOOLEAN.h:19
asn_TYPE_descriptor_s::encoding_constraints
asn_encoding_constraints_t encoding_constraints
Definition: constr_TYPE.h:247
asn_per_constraint_s::upper_bound
intmax_t upper_bound
Definition: per_support.h:28
asn_per_constraint_s::flags
enum asn_per_constraint_s::asn_per_constraint_flags flags


etsi_its_spatem_ts_coding
Author(s): Jean-Pierre Busch , Guido Küppers , Lennart Reiher
autogenerated on Sun May 18 2025 02:29:28