mirror of
git://sigrok.org/libserialport
synced 2023-08-10 21:13:24 +03:00
Clarify sp_list_ports() code.
This also fixes the following scan-build warning: serialport.c:335:15: warning: Result of 'malloc' is converted to a pointer of type 'struct sp_port *', which is incompatible with sizeof operand type 'struct sp_port **' if (!(list = malloc(sizeof(struct sp_port **)))) ^~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~
This commit is contained in:
parent
34442106ef
commit
8d12e620f2
24
serialport.c
24
serialport.c
@ -330,31 +330,27 @@ SP_API enum sp_return sp_list_ports(struct sp_port ***list_ptr)
|
|||||||
if (!list_ptr)
|
if (!list_ptr)
|
||||||
RETURN_ERROR(SP_ERR_ARG, "Null result pointer");
|
RETURN_ERROR(SP_ERR_ARG, "Null result pointer");
|
||||||
|
|
||||||
|
#ifdef NO_ENUMERATION
|
||||||
|
RETURN_ERROR(SP_ERR_SUPP, "Enumeration not supported on this platform");
|
||||||
|
#else
|
||||||
DEBUG("Enumerating ports");
|
DEBUG("Enumerating ports");
|
||||||
|
|
||||||
if (!(list = malloc(sizeof(struct sp_port **))))
|
if (!(list = malloc(sizeof(struct sp_port *))))
|
||||||
RETURN_ERROR(SP_ERR_MEM, "Port list malloc failed");
|
RETURN_ERROR(SP_ERR_MEM, "Port list malloc failed");
|
||||||
|
|
||||||
list[0] = NULL;
|
list[0] = NULL;
|
||||||
|
|
||||||
#ifdef NO_ENUMERATION
|
|
||||||
ret = SP_ERR_SUPP;
|
|
||||||
#else
|
|
||||||
ret = list_ports(&list);
|
ret = list_ports(&list);
|
||||||
#endif
|
|
||||||
|
|
||||||
switch (ret) {
|
if (ret == SP_OK) {
|
||||||
case SP_OK:
|
|
||||||
*list_ptr = list;
|
*list_ptr = list;
|
||||||
RETURN_OK();
|
} else {
|
||||||
case SP_ERR_SUPP:
|
sp_free_port_list(list);
|
||||||
DEBUG_ERROR(SP_ERR_SUPP, "Enumeration not supported on this platform");
|
|
||||||
default:
|
|
||||||
if (list)
|
|
||||||
sp_free_port_list(list);
|
|
||||||
*list_ptr = NULL;
|
*list_ptr = NULL;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RETURN_CODEVAL(ret);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
SP_API void sp_free_port_list(struct sp_port **list)
|
SP_API void sp_free_port_list(struct sp_port **list)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user