Preventive fixes for possible Coverity complaints in the future.

This commit is contained in:
Siarzhuk Zharski 2012-05-18 22:16:41 +02:00
parent 34e730c8fa
commit 80cbddc9f7
3 changed files with 15 additions and 11 deletions

View File

@ -1302,7 +1302,7 @@ AudioControlInterface::_ListFeatureUnitOption(uint32 controlType,
Controls[index].parent = parentIndex;
Controls[index].string = string;
if (name != NULL)
strncpy(Controls[index].name, name, sizeof(Controls[index].name));
strlcpy(Controls[index].name, name, sizeof(Controls[index].name));
if (initGainLimits)
_InitGainLimits(Controls[index]);
@ -1316,7 +1316,7 @@ AudioControlInterface::_ListFeatureUnitOption(uint32 controlType,
Controls[index].master = masterIndex;
Controls[index].string = string;
if (name != NULL)
strncpy(Controls[index].name, name,
strlcpy(Controls[index].name, name,
sizeof(Controls[index].name));
if (initGainLimits)
_InitGainLimits(Controls[index]);
@ -1465,7 +1465,7 @@ AudioControlInterface::_ListSelectorUnitControl(int32& index, int32 parentGroup,
Controls[index].flags = B_MULTI_MIX_MUX;
Controls[index].parent = parentGroup;
Controls[index].string = S_null;
strncpy(Controls[index].name, "Source", sizeof(Controls[index].name));
strlcpy(Controls[index].name, "Source", sizeof(Controls[index].name));
index++;
for (int i = 0; i < selector->fInputPins.Count(); i++) {
@ -1476,7 +1476,7 @@ AudioControlInterface::_ListSelectorUnitControl(int32& index, int32 parentGroup,
Controls[index].parent = recordMUX;
_AudioControl* control = Find(selector->fInputPins[i]);
if (control != NULL) {
strncpy(Controls[index].name,
strlcpy(Controls[index].name,
control->Name(), sizeof(Controls[index].name));
} else {
snprintf(Controls[index].name,
@ -1498,7 +1498,7 @@ AudioControlInterface::_ListMixControlsPage(int32& index,
= Controls[index].id = index | 0x10000;
Controls[index].flags = B_MULTI_MIX_GROUP;
Controls[index].parent = 0;
strncpy(Controls[index].name, Name, sizeof(Controls[index].name));
strlcpy(Controls[index].name, Name, sizeof(Controls[index].name));
index++;
int32 group = groupIndex;

View File

@ -361,10 +361,10 @@ Device::_MultiGetDescription(multi_description *multiDescription)
Description.interface_version = B_CURRENT_INTERFACE_VERSION;
Description.interface_minimum = B_CURRENT_INTERFACE_VERSION;
strncpy(Description.friendly_name, "USB Audio", // TODO: ????
strlcpy(Description.friendly_name, "USB Audio", // TODO: ????
sizeof(Description.friendly_name));
strncpy(Description.vendor_info, "S.Zharski",
strlcpy(Description.vendor_info, "S.Zharski",
sizeof(Description.vendor_info));
Description.output_channel_count = 0;

View File

@ -26,7 +26,9 @@ void create_log()
return;
int flags = O_WRONLY | O_CREAT | ((gTruncateLogFile) ? O_TRUNC : 0);
close(open(gLogFilePath, flags, 0666));
int fd = open(gLogFilePath, flags, 0666);
if (fd >= 0)
close(fd);
mutex_init(&gLogLock, DRIVER_NAME"-logging");
}
@ -77,7 +79,7 @@ void usb_audio_trace(bool force, const char* func, const char *fmt, ...)
static char buffer[1024];
char *buf_ptr = buffer;
if (gLogFilePath == NULL) {
strcpy(buffer, prefix);
strlcpy(buffer, prefix, sizeof(buffer));
buf_ptr += strlen(prefix);
}
@ -106,8 +108,10 @@ void usb_audio_trace(bool force, const char* func, const char *fmt, ...)
mutex_lock(&gLogLock);
int fd = open(gLogFilePath, O_WRONLY | O_APPEND);
write(fd, buffer, strlen(buffer));
close(fd);
if (fd >= 0) {
write(fd, buffer, strlen(buffer));
close(fd);
}
mutex_unlock(&gLogLock);
}