Skip to content

Commit

Permalink
Change data types for DSCP configuration parameters.
Browse files Browse the repository at this point in the history
Addresses MinGW -Wformat warnings because the "hhu" scanf specifier
doesn't seem to be supported in MinGW(x86_64-8.1.0-posix-seh-rt_v6-rev0).
This approach was used instead of the __USE_MINGW_ANSI_STDIO macro
because the latter is a private macro and is probably not intended
for external use.
  • Loading branch information
jvalenzuela committed Oct 9, 2023
1 parent a2858f3 commit 032e340
Showing 1 changed file with 32 additions and 11 deletions.
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

0 comments on commit 032e340

Please sign in to comment.