Skip to content

Commit 9bb3541

Browse files
authored
Merge pull request #25 from sampepose/master
Handle case on mac where product/vendor ID not defined
2 parents 6b4116c + 2246b09 commit 9bb3541

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

mac/platformcontext.mm

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,30 @@ of this software and associated documentation files (the "Software"), to deal
6969

7070
// extract the PID/VID from the model name
7171
NSRange vidRange = [device.modelID rangeOfString:@"VendorID_"];
72-
uint32_t maxLen = device.modelID.length - vidRange.location - 9;
73-
maxLen = (maxLen > 5) ? 5 : maxLen;
74-
deviceInfo->m_vid = [[device.modelID substringWithRange:NSMakeRange(vidRange.location + 9, maxLen)] intValue];
72+
if (vidRange.length > 0)
73+
{
74+
uint32_t maxLen = device.modelID.length - vidRange.location - 9;
75+
maxLen = (maxLen > 5) ? 5 : maxLen;
76+
deviceInfo->m_vid = [[device.modelID substringWithRange:NSMakeRange(vidRange.location + 9, maxLen)] intValue];
77+
}
78+
else
79+
{
80+
LOG(LOG_WARNING, "OSX Unable to extract vendor ID\n");
81+
}
82+
7583

7684
NSRange pidRange = [device.modelID rangeOfString:@"ProductID_"];
77-
maxLen = device.modelID.length - pidRange.location - 10;
78-
maxLen = (maxLen > 5) ? 5 : maxLen;
79-
deviceInfo->m_pid = [[device.modelID substringWithRange:NSMakeRange(pidRange.location + 10, maxLen)] intValue];
85+
if (pidRange.length > 0)
86+
{
87+
uint32_t maxLen = device.modelID.length - pidRange.location - 10;
88+
maxLen = (maxLen > 5) ? 5 : maxLen;
89+
deviceInfo->m_pid = [[device.modelID substringWithRange:NSMakeRange(pidRange.location + 10, maxLen)] intValue];
90+
}
91+
else
92+
{
93+
LOG(LOG_WARNING, "OSX Unable to extract product ID\n");
94+
}
95+
8096

8197
LOG(LOG_DEBUG, "USB : vid=%04X pid=%04X\n", deviceInfo->m_vid, deviceInfo->m_pid);
8298

0 commit comments

Comments
 (0)