Skip to content

Commit b6f8e69

Browse files
committed
fixed: osd name truncated (after v5 bump)
closes #333
1 parent 88894aa commit b6f8e69

File tree

8 files changed

+27
-18
lines changed

8 files changed

+27
-18
lines changed

include/cectypes.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,10 +1466,16 @@ typedef struct ICECCallbacks
14661466
#endif
14671467
} ICECCallbacks;
14681468

1469+
#if CEC_LIB_VERSION_MAJOR >= 5
1470+
#define LIBCEC_OSD_NAME_SIZE (15)
1471+
#else
1472+
#define LIBCEC_OSD_NAME_SIZE (13)
1473+
#endif
1474+
14691475
struct libcec_configuration
14701476
{
14711477
uint32_t clientVersion; /*!< the version of the client that is connecting */
1472-
char strDeviceName[13]; /*!< the device name to use on the CEC bus */
1478+
char strDeviceName[LIBCEC_OSD_NAME_SIZE]; /*!< the device name to use on the CEC bus, name + 0 terminator */
14731479
cec_device_type_list deviceTypes; /*!< the device type(s) to use on the CEC bus for libCEC */
14741480
uint8_t bAutodetectAddress; /*!< (read only) set to 1 by libCEC when the physical address was autodetected */
14751481
uint16_t iPhysicalAddress; /*!< the physical address of the CEC adapter */
@@ -1513,7 +1519,7 @@ struct libcec_configuration
15131519
bool operator==(const libcec_configuration &other) const
15141520
{
15151521
return ( clientVersion == other.clientVersion &&
1516-
!strncmp(strDeviceName, other.strDeviceName, 13) &&
1522+
!strcmp(strDeviceName, other.strDeviceName) &&
15171523
deviceTypes == other.deviceTypes &&
15181524
bAutodetectAddress == other.bAutodetectAddress &&
15191525
iPhysicalAddress == other.iPhysicalAddress &&
@@ -1581,7 +1587,7 @@ struct libcec_configuration
15811587
bAutoPowerOn = 0;
15821588
#endif
15831589

1584-
memset(strDeviceName, 0, 13);
1590+
strDeviceName[0] = (char)0;
15851591
deviceTypes.Clear();
15861592
logicalAddresses.Clear();
15871593
wakeDevices.Clear();

src/cec-client/cec-client.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,7 +1180,7 @@ bool ProcessCommandLineArguments(int argc, char *argv[])
11801180
{
11811181
if (argc >= iArgPtr + 2)
11821182
{
1183-
snprintf(g_config.strDeviceName, 13, "%s", argv[iArgPtr + 1]);
1183+
snprintf(g_config.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", argv[iArgPtr + 1]);
11841184
std::cout << "using osd name " << g_config.strDeviceName << std::endl;
11851185
++iArgPtr;
11861186
}
@@ -1268,7 +1268,7 @@ int main (int argc, char *argv[])
12681268

12691269
g_config.Clear();
12701270
g_callbacks.Clear();
1271-
snprintf(g_config.strDeviceName, 13, "CECTester");
1271+
snprintf(g_config.strDeviceName, LIBCEC_OSD_NAME_SIZE, "CECTester");
12721272
g_config.clientVersion = LIBCEC_VERSION_CURRENT;
12731273
g_config.bActivateSource = 0;
12741274
g_callbacks.logMessage = &CecLogMessage;

src/libcec/CECClient.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,7 @@ bool CCECClient::GetCurrentConfiguration(libcec_configuration &configuration)
847847
{
848848
CLockObject lock(m_mutex);
849849

850-
snprintf(configuration.strDeviceName, 13, "%s", m_configuration.strDeviceName);
850+
snprintf(configuration.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", m_configuration.strDeviceName);
851851
configuration.deviceTypes = m_configuration.deviceTypes;
852852
configuration.bAutodetectAddress = m_configuration.bAutodetectAddress;
853853
configuration.iPhysicalAddress = m_configuration.iPhysicalAddress;
@@ -1274,7 +1274,7 @@ void CCECClient::SetOSDName(const std::string &strDeviceName)
12741274
{
12751275
{
12761276
CLockObject lock(m_mutex);
1277-
snprintf(m_configuration.strDeviceName, 13, "%s", strDeviceName.c_str());
1277+
snprintf(m_configuration.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", strDeviceName.c_str());
12781278
}
12791279

12801280
LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - using OSD name '%s'", __FUNCTION__, strDeviceName.c_str());
@@ -1717,4 +1717,4 @@ bool CCECClient::GetStats(struct cec_adapter_stats* stats)
17171717
m_processor->GetStats(stats) :
17181718
false;
17191719
}
1720-
#endif
1720+
#endif

src/libcec/CECProcessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ bool CCECProcessor::RegisterClient(CECClientPtr client)
899899
configuration.deviceTypes = config.deviceTypes;
900900
if (CLibCEC::IsValidPhysicalAddress(config.iPhysicalAddress))
901901
configuration.iPhysicalAddress = config.iPhysicalAddress;
902-
snprintf(configuration.strDeviceName, 13, "%s", config.strDeviceName);
902+
snprintf(configuration.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", config.strDeviceName);
903903
}
904904

905905
// set the firmware version and build date

src/libcec/LibCEC.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ void * CECInit(const char *strDeviceName, CEC::cec_device_type_list types)
455455
libcec_configuration configuration; configuration.Clear();
456456

457457
// client version < 1.5.0
458-
snprintf(configuration.strDeviceName, 13, "%s", strDeviceName);
458+
snprintf(configuration.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", strDeviceName);
459459
configuration.deviceTypes = types;
460460
configuration.iPhysicalAddress = CEC_INVALID_PHYSICAL_ADDRESS;
461461

@@ -632,4 +632,4 @@ bool CLibCEC::GetStats(struct cec_adapter_stats* stats)
632632
m_client->GetStats(stats) :
633633
false;
634634
}
635-
#endif
635+
#endif

src/libcec/LibCECC.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,10 @@ int libcec_get_device_osd_name(libcec_connection_t connection, cec_logical_addre
354354
if (!!adapter)
355355
{
356356
std::string osdName(adapter->GetDeviceOSDName(iAddress));
357-
strncpy(name, osdName.c_str(), std::min(sizeof(cec_osd_name), osdName.size()));
357+
size_t osd_size(osdName.size());
358+
memcpy(name, osdName.c_str(), std::min(sizeof(cec_osd_name), osd_size));
359+
if (osd_size < sizeof(cec_osd_name))
360+
name[osd_size] = (char)0;
358361
return 0;
359362
}
360363
return -1;

src/libcec/adapter/Pulse-Eight/USBCECAdapterCommands.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,12 @@ bool CUSBCECAdapterCommands::RequestSettingOSDName(void)
253253
if (response.size == 0)
254254
{
255255
LIB_CEC->AddLog(CEC_LOG_DEBUG, "no persisted device name setting");
256-
memset(m_persistedConfiguration.strDeviceName, 0, 13);
256+
m_persistedConfiguration.strDeviceName[0] = (char)0;
257257
return false;
258258
}
259259

260-
memcpy(m_persistedConfiguration.strDeviceName, response.data, response.size <= 13 ? response.size : 13);
261-
if (response.size < 13) {
260+
memcpy(m_persistedConfiguration.strDeviceName, response.data, response.size <= LIBCEC_OSD_NAME_SIZE ? response.size : LIBCEC_OSD_NAME_SIZE);
261+
if (response.size < LIBCEC_OSD_NAME_SIZE) {
262262
m_persistedConfiguration.strDeviceName[response.size] = (char)0;
263263
}
264264
return true;
@@ -511,7 +511,7 @@ bool CUSBCECAdapterCommands::SetSettingOSDName(const char *strOSDName)
511511
SAFE_DELETE(message);
512512

513513
if (bReturn)
514-
snprintf(m_persistedConfiguration.strDeviceName, 13, "%s", strOSDName);
514+
snprintf(m_persistedConfiguration.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", strOSDName);
515515

516516
return bReturn;
517517
}
@@ -623,7 +623,7 @@ bool CUSBCECAdapterCommands::GetConfiguration(libcec_configuration &configuratio
623623
configuration.iFirmwareVersion = m_persistedConfiguration.iFirmwareVersion;
624624
configuration.deviceTypes = m_persistedConfiguration.deviceTypes;
625625
configuration.iPhysicalAddress = m_persistedConfiguration.iPhysicalAddress;
626-
snprintf(configuration.strDeviceName, 13, "%s", m_persistedConfiguration.strDeviceName);
626+
snprintf(configuration.strDeviceName, LIBCEC_OSD_NAME_SIZE, "%s", m_persistedConfiguration.strDeviceName);
627627

628628
return true;
629629
}

src/libcec/implementations/CECCommandHandler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ int CCECCommandHandler::HandleSetOSDName(const cec_command &command)
616616
CCECBusDevice *device = GetDevice(command.initiator);
617617
if (device)
618618
{
619-
char buf[1024];
619+
char buf[17];
620620
for (uint8_t iPtr = 0; iPtr < command.parameters.size; iPtr++)
621621
buf[iPtr] = (char)command.parameters[iPtr];
622622
buf[command.parameters.size] = 0;

0 commit comments

Comments
 (0)