Fix cppcheck warning "buffer may not be null-terminated after call to strncpy()"

This commit is contained in:
Philippe Teuwen 2013-03-06 12:38:59 +01:00
parent 3e773ab494
commit 1d5f9956fb
5 changed files with 5 additions and 0 deletions

View file

@ -271,6 +271,7 @@ acr122_pcsc_open(const nfc_context *context, const nfc_connstring connstring)
return NULL; return NULL;
} }
strncpy(fullconnstring, ncs[index], sizeof(nfc_connstring)); strncpy(fullconnstring, ncs[index], sizeof(nfc_connstring));
fullconnstring[sizeof(nfc_connstring) - 1] = '\0';
free(ncs); free(ncs);
connstring_decode_level = acr122_pcsc_connstring_decode(fullconnstring, &ndd); connstring_decode_level = acr122_pcsc_connstring_decode(fullconnstring, &ndd);
if (connstring_decode_level < 2) { if (connstring_decode_level < 2) {

View file

@ -410,6 +410,7 @@ acr122_usb_get_usb_device_name(struct usb_device *dev, usb_dev_handle *udev, cha
if ((acr122_usb_supported_devices[n].vendor_id == dev->descriptor.idVendor) && if ((acr122_usb_supported_devices[n].vendor_id == dev->descriptor.idVendor) &&
(acr122_usb_supported_devices[n].product_id == dev->descriptor.idProduct)) { (acr122_usb_supported_devices[n].product_id == dev->descriptor.idProduct)) {
strncpy(buffer, acr122_usb_supported_devices[n].name, len); strncpy(buffer, acr122_usb_supported_devices[n].name, len);
buffer[len - 1] = '\0';
return true; return true;
} }
} }

View file

@ -295,6 +295,7 @@ pn53x_usb_get_usb_device_name(struct usb_device *dev, usb_dev_handle *udev, char
if ((pn53x_usb_supported_devices[n].vendor_id == dev->descriptor.idVendor) && if ((pn53x_usb_supported_devices[n].vendor_id == dev->descriptor.idVendor) &&
(pn53x_usb_supported_devices[n].product_id == dev->descriptor.idProduct)) { (pn53x_usb_supported_devices[n].product_id == dev->descriptor.idProduct)) {
strncpy(buffer, pn53x_usb_supported_devices[n].name, len); strncpy(buffer, pn53x_usb_supported_devices[n].name, len);
buffer[len - 1] = '\0';
return true; return true;
} }
} }

View file

@ -226,6 +226,7 @@ nfc_open(nfc_context *context, const nfc_connstring connstring)
} }
} else { } else {
strncpy(ncs, connstring, sizeof(nfc_connstring)); strncpy(ncs, connstring, sizeof(nfc_connstring));
ncs[sizeof(nfc_connstring) - 1] = '\0';
} }
// Search through the device list for an available device // Search through the device list for an available device

View file

@ -130,6 +130,7 @@ static int scan_hex_fd3(uint8_t *pbtData, size_t *pszBytes, const char *pchPrefi
} }
} }
strncpy(pchScan, pchPrefix, 250); strncpy(pchScan, pchPrefix, 250);
pchScan[sizeof(pchScan) - 1] = '\0';
strcat(pchScan, " %04x:"); strcat(pchScan, " %04x:");
if (fscanf(fd3, pchScan, &uiBytes) < 1) { if (fscanf(fd3, pchScan, &uiBytes) < 1) {
return -1; return -1;