Skip to content

Commit

Permalink
Add null char to device name
Browse files Browse the repository at this point in the history
  • Loading branch information
YaSuenag committed Jul 4, 2024
1 parent 14a84fc commit 2d910a9
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion SimpleCom/SerialDeviceScanner.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023, Yasumasa Suenaga
* Copyright (C) 2023, 2024, Yasumasa Suenaga
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -184,6 +184,9 @@ void SimpleCom::SerialDeviceScanner::ScanSerialDevices() {

status = RegEnumValue(hKey, idx, InterfaceName, &ValueNameLen, NULL, NULL, reinterpret_cast<LPBYTE>(DeviceName), &ValueLen);
if (status == ERROR_SUCCESS) {
// DeviceName (lpData in RegEnumValue) might not be null-terminated, so we need to add null char (0).
// This argument is defined as LPBYTE, so we need to divide the length with sizeof(TCHAR).
DeviceName[ValueLen / sizeof(TCHAR)] = 0;
_devices[DeviceName] = InterfaceName;
}

Expand Down

0 comments on commit 2d910a9

Please sign in to comment.