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:
parent
f87720dff9
commit
42f8e012b7
@ -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_status_t status = DC_STATUS_SUCCESS;
|
||||||
dc_serial_t *device = NULL;
|
dc_serial_t *device = NULL;
|
||||||
|
|
||||||
if (out == NULL)
|
if (out == NULL || name == NULL)
|
||||||
return DC_STATUS_INVALIDARGS;
|
return DC_STATUS_INVALIDARGS;
|
||||||
|
|
||||||
INFO (context, "Open: name=%s", name ? name : "");
|
INFO (context, "Open: name=%s", name);
|
||||||
|
|
||||||
// Allocate memory.
|
// Allocate memory.
|
||||||
device = (dc_serial_t *) dc_iostream_allocate (context, &dc_serial_vtable);
|
device = (dc_serial_t *) dc_iostream_allocate (context, &dc_serial_vtable);
|
||||||
|
|||||||
@ -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_status_t status = DC_STATUS_SUCCESS;
|
||||||
dc_serial_t *device = NULL;
|
dc_serial_t *device = NULL;
|
||||||
|
|
||||||
if (out == NULL)
|
if (out == NULL || name == NULL)
|
||||||
return DC_STATUS_INVALIDARGS;
|
return DC_STATUS_INVALIDARGS;
|
||||||
|
|
||||||
INFO (context, "Open: name=%s", name ? name : "");
|
INFO (context, "Open: name=%s", name);
|
||||||
|
|
||||||
// Build the device name.
|
// Build the device name.
|
||||||
const char *devname = NULL;
|
const char *devname = NULL;
|
||||||
char buffer[MAX_PATH] = "\\\\.\\";
|
char buffer[MAX_PATH] = "\\\\.\\";
|
||||||
if (name && strncmp (name, buffer, 4) != 0) {
|
if (strncmp (name, buffer, 4) != 0) {
|
||||||
size_t length = strlen (name) + 1;
|
size_t length = strlen (name) + 1;
|
||||||
if (length + 4 > sizeof (buffer))
|
if (length + 4 > sizeof (buffer))
|
||||||
return DC_STATUS_NOMEMORY;
|
return DC_STATUS_NOMEMORY;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user