Update hid.c to fix MSYS2 MinGW-w64 compiler warning (#311)

This fixed a compiler warning when using MSYS2 MinGW-w64 compiler as mentioned in issue #289.

Since we changed strncpy to memcpy, it is not necessary to disable warning 4996 for MSVC.
This commit is contained in:
mcuee
2021-07-27 18:02:57 +08:00
committed by GitHub
parent ac8c9e5f94
commit 8741697359

View File

@@ -63,18 +63,13 @@ extern "C" {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hidapi.h"
#undef MIN
#define MIN(x,y) ((x) < (y)? (x): (y))
#ifdef _MSC_VER
/* Thanks Microsoft, but I know how to use strncpy(). */
#pragma warning(disable:4996)
#endif
#ifdef __cplusplus
extern "C" {
#endif
@@ -330,8 +325,7 @@ static struct hid_device_info *hid_get_device_info(const char *path, HANDLE hand
if (path) {
size_t len = strlen(path);
dev->path = (char*)calloc(len + 1, sizeof(char));
strncpy(dev->path, path, len + 1);
dev->path[len] = '\0';
memcpy(dev->path, path, len + 1);
}
else
dev->path = NULL;