From 907a46213e5ca3e741744f67ad71966b70b89e38 Mon Sep 17 00:00:00 2001
From: gcontini <1121667+gcontini@users.noreply.github.com>
Date: 周六, 05 12月 2020 23:38:40 +0800
Subject: [PATCH] fix Codacy warnings

---
 src/library/os/windows/os_win.cpp |    9 +++++----
 1 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/library/os/windows/os_win.cpp b/src/library/os/windows/os_win.cpp
index 54dbc75..73ed550 100644
--- a/src/library/os/windows/os_win.cpp
+++ b/src/library/os/windows/os_win.cpp
@@ -5,6 +5,7 @@
 #include <iphlpapi.h>
 #include <stdio.h>
 
+#include "../../base/string_utils.h"
 #include "../../base/logger.h"
 #include "../os.h"
 using namespace std;
@@ -29,7 +30,7 @@
 	DWORD fileMaxLen;
 	size_t ndrives = 0, drives_scanned = 0;
 	DWORD fileFlags;
-	char volName[MAX_PATH], fileSysName[MAX_PATH];
+	char volName[MAX_PATH];
 	DWORD volSerial = 0;
 	const DWORD dwSize = MAX_PATH;
 	char szLogicalDrives[MAX_PATH] = {0};
@@ -44,6 +45,7 @@
 			// get the next drive
 			UINT driveType = GetDriveType(szSingleDrive);
 			if (driveType == DRIVE_FIXED) {
+				char fileSysName[MAX_PATH];
 				BOOL success = GetVolumeInformation(szSingleDrive, volName, MAX_PATH, &volSerial, &fileMaxLen,
 													&fileFlags, fileSysName, MAX_PATH);
 				if (success) {
@@ -52,9 +54,8 @@
 					DiskInfo diskInfo = {};
 					diskInfo.id = (int)ndrives;
 					diskInfo.label_initialized = true;
-					strncpy(diskInfo.device, volName, min(std::size_t{MAX_PATH}, sizeof(volName)) - 1);
-					strncpy(diskInfo.label, fileSysName,
-							min(sizeof(diskInfos[ndrives].label), sizeof(fileSysName)) - 1);
+					mstrlcpy(diskInfo.device, volName, min(std::size_t{MAX_PATH}, sizeof(volName)));
+					mstrlcpy(diskInfo.label, fileSysName, min(sizeof(diskInfos[ndrives].label), sizeof(fileSysName)));
 					memcpy(diskInfo.disk_sn, &volSerial, sizeof(DWORD));
 					diskInfo.sn_initialized = true;
 					diskInfo.preferred = (szSingleDrive[0] == 'C');

--
Gitblit v1.9.1