#include "serialport.h"
-static struct sp_port *sp_port_new(char *portname, size_t len)
+static struct sp_port *sp_port_new(const char *portname)
{
struct sp_port *port;
+ int len;
if (!(port = malloc(sizeof(struct sp_port))))
return NULL;
+ len = strlen(portname) + 1;
+
if (!(port->name = malloc(len)))
{
free(port);
return port;
}
-static struct sp_port **sp_list_append(struct sp_port **list, char *portname, size_t len)
+static struct sp_port **sp_list_append(struct sp_port **list, const char *portname)
{
void *tmp;
unsigned int count;
if (!(tmp = realloc(list, sizeof(struct sp_port *) * (count + 2))))
goto fail;
list = tmp;
- if (!(list[count] = sp_port_new(portname, len)))
+ if (!(list[count] = sp_port_new(portname)))
goto fail;
list[count + 1] = NULL;
return list;
strcpy(name, data);
#endif
if (type == REG_SZ)
- if (!(list = sp_list_append(list, name, name_len)))
+ if (!(list = sp_list_append(list, name)))
goto out;
index++;
}
path, PATH_MAX, kCFStringEncodingASCII);
CFRelease(cf_path);
if (result)
- if (!(list = sp_list_append(list, path, strlen(path) + 1)))
+ if (!(list = sp_list_append(list, path)))
{
IOObjectRelease(port);
goto out;
if (serial_info.type == PORT_UNKNOWN)
goto skip;
}
- list = sp_list_append(list, (void *)name, strlen(name) + 1);
+ list = sp_list_append(list, name);
skip:
udev_device_unref(ud_dev);
if (!list)