Use "strlcpy" instead of "strncpy" and other Coverity issues

* Yet more nice way to fix Coverity issues fixed by hrev43460.
  Thanks Rene Gollent for pointing it out!
* Potential Coverity issues fixed for sis19x driver too.
This commit is contained in:
Siarzhuk Zharski
2011-12-10 21:52:16 +01:00
parent e339322a88
commit eed9bc771c
6 changed files with 17 additions and 12 deletions
@@ -337,10 +337,10 @@ Device::_MultiGetDescription(multi_description *multiDescription)
Description.interface_version = B_CURRENT_INTERFACE_VERSION; Description.interface_version = B_CURRENT_INTERFACE_VERSION;
Description.interface_minimum = B_CURRENT_INTERFACE_VERSION; Description.interface_minimum = B_CURRENT_INTERFACE_VERSION;
strncpy(Description.friendly_name, fInfo.Name(), strlcpy(Description.friendly_name, fInfo.Name(),
sizeof(Description.friendly_name) - 1); sizeof(Description.friendly_name));
strncpy(Description.vendor_info, "Haiku.Inc.", strlcpy(Description.vendor_info, "Haiku.Inc.",
sizeof(Description.vendor_info)); sizeof(Description.vendor_info));
Description.output_channel_count = 2; Description.output_channel_count = 2;
@@ -478,7 +478,7 @@ Mixer::_CreateMIXControlGroup(multi_mix_control_info* MultiInfo, int32& index,
Controls[index].string = Info.fNameId; Controls[index].string = Info.fNameId;
if (Info.fName != NULL) if (Info.fName != NULL)
strlcpy(Controls[index].name, Info.fName, strlcpy(Controls[index].name, Info.fName,
sizeof(Controls[index].name) - 1); sizeof(Controls[index].name));
index++; index++;
if (Info.fType & MIX_Mute) { if (Info.fType & MIX_Mute) {
@@ -549,7 +549,8 @@ Mixer::_CreateMIXControlGroup(multi_mix_control_info* MultiInfo, int32& index,
Controls[index].flags = B_MULTI_MIX_MUX; Controls[index].flags = B_MULTI_MIX_MUX;
Controls[index].parent = groupIndex; Controls[index].parent = groupIndex;
Controls[index].string = S_null; Controls[index].string = S_null;
strlcpy(Controls[index].name, Info.fExName, sizeof(Controls[index].name)); strlcpy(Controls[index].name, Info.fExName,
sizeof(Controls[index].name));
TRACE("MUX:%#010x\n", Controls[index].id); TRACE("MUX:%#010x\n", Controls[index].id);
index++; index++;
@@ -79,7 +79,7 @@ void SiS7018_trace(bool force, const char* func, const char *fmt, ...)
static char buffer[1024]; static char buffer[1024];
char *buf_ptr = buffer; char *buf_ptr = buffer;
if (gLogFilePath == NULL) { if (gLogFilePath == NULL) {
strncpy(buffer, prefix, sizeof(buffer) - 1); strlcpy(buffer, prefix, sizeof(buffer));
buf_ptr += strlen(prefix); buf_ptr += strlen(prefix);
} }
@@ -35,7 +35,9 @@ void create_log()
return; return;
int flags = O_WRONLY | O_CREAT | ((gTruncateLogFile) ? O_TRUNC : 0); 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"); mutex_init(&gLogLock, DRIVER_NAME"-logging");
} }
@@ -91,7 +93,7 @@ void SiS19X_trace(bool force, const char* func, const char *fmt, ...)
static char buffer[1024]; static char buffer[1024];
char *buf_ptr = buffer; char *buf_ptr = buffer;
if (gLogFilePath == NULL) { if (gLogFilePath == NULL) {
strcpy(buffer, prefix); strlcpy(buffer, prefix, sizeof(buffer));
buf_ptr += strlen(prefix); buf_ptr += strlen(prefix);
} }
@@ -120,8 +122,10 @@ void SiS19X_trace(bool force, const char* func, const char *fmt, ...)
mutex_lock(&gLogLock); mutex_lock(&gLogLock);
int fd = open(gLogFilePath, O_WRONLY | O_APPEND); int fd = open(gLogFilePath, O_WRONLY | O_APPEND);
write(fd, buffer, strlen(buffer)); if (fd > 0) {
close(fd); write(fd, buffer, strlen(buffer));
close(fd);
}
mutex_unlock(&gLogLock); mutex_unlock(&gLogLock);
} }
@@ -88,7 +88,7 @@ void usb_asix_trace(bool force, const char* func, const char *fmt, ...)
static char buffer[1024]; static char buffer[1024];
char *buf_ptr = buffer; char *buf_ptr = buffer;
if (gLogFilePath == NULL) { if (gLogFilePath == NULL) {
strncpy(buffer, prefix, sizeof(buffer) - 1); strlcpy(buffer, prefix, sizeof(buffer));
buf_ptr += strlen(prefix); buf_ptr += strlen(prefix);
} }
@@ -95,7 +95,7 @@ void usb_davicom_trace(bool force, const char* func, const char *fmt, ...)
static char buffer[1024]; static char buffer[1024];
char *buf_ptr = buffer; char *buf_ptr = buffer;
if (gLogFilePath == NULL) { if (gLogFilePath == NULL) {
strncpy(buffer, prefix, sizeof(buffer) - 1); strlcpy(buffer, prefix, sizeof(buffer));
buf_ptr += strlen(prefix); buf_ptr += strlen(prefix);
} }