mirror of git://git.sysmocom.de/ofono
qmimodem: Fix format warning
../../drivers/qmimodem/network-registration.c: In function ‘extract_ss_info’: ../../drivers/qmimodem/network-registration.c:131:54: warning: ‘%03d’ directive output may be truncated writing between 3 and 5 bytes into a region of size 4 [-Wformat-truncation=] 131 | snprintf(operator->mcc, OFONO_MAX_MCC_LENGTH + 1, "%03d", | ^~~~ ../../drivers/qmimodem/network-registration.c:131:53: note: directive argument in the range [0, 65535] 131 | snprintf(operator->mcc, OFONO_MAX_MCC_LENGTH + 1, "%03d", | ^~~~~~ The MCC/MNC fields are limited to three digits. Clamp the input to 999 to avoid the warning.
This commit is contained in:
parent
23e1a56a47
commit
52091a1af0
|
@ -128,10 +128,18 @@ static bool extract_ss_info(struct qmi_result *result, int *status,
|
||||||
|
|
||||||
plmn = qmi_result_get(result, QMI_NAS_RESULT_CURRENT_PLMN, &len);
|
plmn = qmi_result_get(result, QMI_NAS_RESULT_CURRENT_PLMN, &len);
|
||||||
if (plmn) {
|
if (plmn) {
|
||||||
snprintf(operator->mcc, OFONO_MAX_MCC_LENGTH + 1, "%03d",
|
uint16_t mcc = GUINT16_FROM_LE(plmn->mcc);
|
||||||
GUINT16_FROM_LE(plmn->mcc));
|
uint16_t mnc = GUINT16_FROM_LE(plmn->mnc);
|
||||||
snprintf(operator->mnc, OFONO_MAX_MNC_LENGTH + 1, "%02d",
|
|
||||||
GUINT16_FROM_LE(plmn->mnc));
|
if (mcc > 999)
|
||||||
|
mcc = 999;
|
||||||
|
|
||||||
|
if (mnc > 999)
|
||||||
|
mnc = 999;
|
||||||
|
|
||||||
|
snprintf(operator->mcc, OFONO_MAX_MCC_LENGTH + 1, "%03d", mcc);
|
||||||
|
snprintf(operator->mnc, OFONO_MAX_MNC_LENGTH + 1, "%03d", mnc);
|
||||||
|
|
||||||
opname_len = plmn->desc_len;
|
opname_len = plmn->desc_len;
|
||||||
if (opname_len > OFONO_MAX_OPERATOR_NAME_LENGTH)
|
if (opname_len > OFONO_MAX_OPERATOR_NAME_LENGTH)
|
||||||
opname_len = OFONO_MAX_OPERATOR_NAME_LENGTH;
|
opname_len = OFONO_MAX_OPERATOR_NAME_LENGTH;
|
||||||
|
@ -311,11 +319,17 @@ static void scan_nets_cb(struct qmi_result *result, void *user_data)
|
||||||
|
|
||||||
for (i = 0; i < num; i++) {
|
for (i = 0; i < num; i++) {
|
||||||
const struct qmi_nas_network_info *netinfo = ptr + offset;
|
const struct qmi_nas_network_info *netinfo = ptr + offset;
|
||||||
|
uint16_t mcc = GUINT16_FROM_LE(netinfo->mcc);
|
||||||
|
uint16_t mnc = GUINT16_FROM_LE(netinfo->mnc);
|
||||||
|
|
||||||
snprintf(list[i].mcc, OFONO_MAX_MCC_LENGTH + 1, "%03d",
|
if (mcc > 999)
|
||||||
GUINT16_FROM_LE(netinfo->mcc));
|
mcc = 999;
|
||||||
snprintf(list[i].mnc, OFONO_MAX_MNC_LENGTH + 1, "%02d",
|
|
||||||
GUINT16_FROM_LE(netinfo->mnc));
|
if (mnc > 999)
|
||||||
|
mnc = 999;
|
||||||
|
|
||||||
|
snprintf(list[i].mcc, OFONO_MAX_MCC_LENGTH + 1, "%03d", mcc);
|
||||||
|
snprintf(list[i].mnc, OFONO_MAX_MNC_LENGTH + 1, "%03d", mnc);
|
||||||
strncpy(list[i].name, netinfo->desc, netinfo->desc_len);
|
strncpy(list[i].name, netinfo->desc, netinfo->desc_len);
|
||||||
list[i].name[netinfo->desc_len] = '\0';
|
list[i].name[netinfo->desc_len] = '\0';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue