Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change data types for DSCP configuration parameters. #478

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 32 additions & 11 deletions source/src/ports/nvdata/nvqos.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "nvqos.h"

#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>

Expand All @@ -32,11 +33,18 @@ int NvQosLoad(CipQosObject *p_qos) {
int rd_cnt = 0;
EipStatus eip_status = kEipStatusError;

CipUsint dscp_urgent = 0;
CipUsint dscp_scheduled = 0;
CipUsint dscp_high = 0;
CipUsint dscp_low = 0;
CipUsint dscp_explicit = 0;
/*
* Data type for these parameters explicitly differs from the specification(CipUsint),
* because the required scanf specifier to read that type, "hhu", is not supported
* in MinGW. The generic unsigned type is used instead, which is guaranteed to fit
* a CipUsint, followed by a check after scanf to ensure valid values before
* casting them to CipUsint upon assignment to the output structure.
*/
unsigned int dscp_urgent = 0;
unsigned int dscp_scheduled = 0;
unsigned int dscp_high = 0;
unsigned int dscp_low = 0;
unsigned int dscp_explicit = 0;

FILE *p_file = ConfFileOpen(false, QOS_CFG_NAME);
if (NULL != p_file) {
Expand All @@ -48,7 +56,7 @@ int NvQosLoad(CipQosObject *p_qos) {

/* Read input data */
rd_cnt = fscanf(p_file,
" %" SCNu8 ", %" SCNu8 ", %" SCNu8 ", %" SCNu8 ", %" SCNu8 "\n",
" %u, %u, %u, %u, %u\n",
&dscp_urgent,
&dscp_scheduled,
&dscp_high,
Expand All @@ -64,13 +72,26 @@ int NvQosLoad(CipQosObject *p_qos) {
eip_status = ConfFileClose(&p_file);
}
if (kEipStatusOk == eip_status) {

/*
* Ensure all values read from the configuration file are within the CipUsint range;
* see above comments for these dscp_* local variables for details.
*/
if ( (dscp_urgent > UCHAR_MAX)
|| (dscp_scheduled > UCHAR_MAX)
|| (dscp_high > UCHAR_MAX)
|| (dscp_low > UCHAR_MAX)
|| (dscp_explicit > UCHAR_MAX) ) {
rd_cnt = 0;
}

/* If all data were read copy them to the global QoS object. */
if (5 == rd_cnt) {
p_qos->dscp.urgent = dscp_urgent;
p_qos->dscp.scheduled = dscp_scheduled;
p_qos->dscp.high = dscp_high;
p_qos->dscp.low = dscp_low;
p_qos->dscp.explicit_msg = dscp_explicit;
p_qos->dscp.urgent = (CipUsint)dscp_urgent;
p_qos->dscp.scheduled = (CipUsint)dscp_scheduled;
p_qos->dscp.high = (CipUsint)dscp_high;
p_qos->dscp.low = (CipUsint)dscp_low;
p_qos->dscp.explicit_msg = (CipUsint)dscp_explicit;
} else {
eip_status = kEipStatusError;
}
Expand Down
Loading