aboutsummaryrefslogtreecommitdiffstats
path: root/src/gprs/gprs_sndcp_comp.c
diff options
context:
space:
mode:
authorStefan Sperling <ssperling@sysmocom.de>2018-11-07 16:33:39 +0100
committerStefan Sperling <ssperling@sysmocom.de>2018-11-15 15:57:59 +0100
commitc5721545c6cd69effcef612a14c01aa4be89adde (patch)
tree97fd63dfe4a622a5a4385517ebbef68ca6a190bb /src/gprs/gprs_sndcp_comp.c
parent60509688527efdf2a90b2d4241034a9775898940 (diff)
use enums consistently instead of falling back to int
The two existing enums defined in gprs_sndcp_xid.h, for protocol and data compression algorithm numbers respectively, were assigned to 'int' variables when their values were copied to other structures. This prevented the compiler from checking the enum value coverage during switch statements and also tripped up Coverity scans looking for enum value mismatch problems. So instead of copying enums to ints, make use of the enums throughout. Structures which can contain values from both enums now use a union of both, forcing us to be very explicit about which set of values we are dealing with. Change-Id: I3771a5c59f4e6fee24083b3c914965baf192cbd7 Depends: If6f3598cd6da4643ff2214e21c0d21f6eff0eb67 Depends: I8444c1ed052707c76a979fb06cb018ac678defa7 Related: CID#149102
Diffstat (limited to 'src/gprs/gprs_sndcp_comp.c')
-rw-r--r--src/gprs/gprs_sndcp_comp.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/gprs/gprs_sndcp_comp.c b/src/gprs/gprs_sndcp_comp.c
index 3e026032e..0b4c67cd4 100644
--- a/src/gprs/gprs_sndcp_comp.c
+++ b/src/gprs/gprs_sndcp_comp.c
@@ -55,32 +55,36 @@ static struct gprs_sndcp_comp *gprs_sndcp_comp_create(const void *ctx,
memcpy(comp_entity->nsapi,
comp_field->rfc1144_params->nsapi,
sizeof(comp_entity->nsapi));
+ comp_entity->algo.pcomp = comp_field->algo.pcomp;
} else if (comp_field->rfc2507_params) {
comp_entity->nsapi_len = comp_field->rfc2507_params->nsapi_len;
memcpy(comp_entity->nsapi,
comp_field->rfc2507_params->nsapi,
sizeof(comp_entity->nsapi));
+ comp_entity->algo.pcomp = comp_field->algo.pcomp;
} else if (comp_field->rohc_params) {
comp_entity->nsapi_len = comp_field->rohc_params->nsapi_len;
memcpy(comp_entity->nsapi, comp_field->rohc_params->nsapi,
sizeof(comp_entity->nsapi));
+ comp_entity->algo.pcomp = comp_field->algo.pcomp;
} else if (comp_field->v42bis_params) {
comp_entity->nsapi_len = comp_field->v42bis_params->nsapi_len;
memcpy(comp_entity->nsapi,
comp_field->v42bis_params->nsapi,
sizeof(comp_entity->nsapi));
+ comp_entity->algo.dcomp = comp_field->algo.dcomp;
} else if (comp_field->v44_params) {
comp_entity->nsapi_len = comp_field->v44_params->nsapi_len;
memcpy(comp_entity->nsapi,
comp_field->v44_params->nsapi,
sizeof(comp_entity->nsapi));
+ comp_entity->algo.dcomp = comp_field->algo.dcomp;
} else {
/* The caller is expected to check carefully if the all
* data fields required for compression entity creation
* are present. Otherwise we blow an assertion here */
OSMO_ASSERT(false);
}
- comp_entity->algo = comp_field->algo;
/* Check if an NSAPI is selected, if not, it does not make sense
* to create the compression entity, since the caller should
@@ -93,17 +97,20 @@ static struct gprs_sndcp_comp *gprs_sndcp_comp_create(const void *ctx,
comp_entity->compclass = gprs_sndcp_get_compression_class(comp_field);
/* Create an algorithm specific compression context */
- if (comp_entity->compclass == SNDCP_XID_PROTOCOL_COMPRESSION) {
+ switch (comp_entity->compclass) {
+ case SNDCP_XID_PROTOCOL_COMPRESSION:
if (gprs_sndcp_pcomp_init(ctx, comp_entity, comp_field) != 0) {
talloc_free(comp_entity);
comp_entity = NULL;
}
- } else if (comp_entity->compclass == SNDCP_XID_DATA_COMPRESSION) {
+ break;
+ case SNDCP_XID_DATA_COMPRESSION:
if (gprs_sndcp_dcomp_init(ctx, comp_entity, comp_field) != 0) {
talloc_free(comp_entity);
comp_entity = NULL;
}
- } else {
+ break;
+ default:
/* comp_field is somehow invalid */
OSMO_ASSERT(false);
}