Don't accept a NULL pointer as parameter

Immediately return an error instead of trying to pass the NULL pointer
to the underlying open system call.
This commit is contained in:
Jef Driesen 2017-11-30 22:47:12 +01:00
parent f87720dff9
commit 42f8e012b7
2 changed files with 5 additions and 5 deletions

View File

@ -181,10 +181,10 @@ dc_serial_open (dc_iostream_t **out, dc_context_t *context, const char *name)
dc_status_t status = DC_STATUS_SUCCESS;
dc_serial_t *device = NULL;
if (out == NULL)
if (out == NULL || name == NULL)
return DC_STATUS_INVALIDARGS;
INFO (context, "Open: name=%s", name ? name : "");
INFO (context, "Open: name=%s", name);
// Allocate memory.
device = (dc_serial_t *) dc_iostream_allocate (context, &dc_serial_vtable);

View File

@ -161,15 +161,15 @@ dc_serial_open (dc_iostream_t **out, dc_context_t *context, const char *name)
dc_status_t status = DC_STATUS_SUCCESS;
dc_serial_t *device = NULL;
if (out == NULL)
if (out == NULL || name == NULL)
return DC_STATUS_INVALIDARGS;
INFO (context, "Open: name=%s", name ? name : "");
INFO (context, "Open: name=%s", name);
// Build the device name.
const char *devname = NULL;
char buffer[MAX_PATH] = "\\\\.\\";
if (name && strncmp (name, buffer, 4) != 0) {
if (strncmp (name, buffer, 4) != 0) {
size_t length = strlen (name) + 1;
if (length + 4 > sizeof (buffer))
return DC_STATUS_NOMEMORY;