Always initialize the output parameters
I/O functions with output parameters, should always initialize those output parameters, even when an error is returned. This prevents the (accidental) use of uninitialized variables, whenever the caller forgets to check the return code. As a nice side effect, the use of a local variable guarantees that the underlying I/O implementation will always receive a valid pointer.
This commit is contained in:
@@ -131,19 +131,41 @@ dc_iostream_set_rts (dc_iostream_t *iostream, unsigned int value)
|
|||||||
dc_status_t
|
dc_status_t
|
||||||
dc_iostream_get_lines (dc_iostream_t *iostream, unsigned int *value)
|
dc_iostream_get_lines (dc_iostream_t *iostream, unsigned int *value)
|
||||||
{
|
{
|
||||||
if (iostream == NULL || iostream->vtable->get_lines == NULL)
|
dc_status_t status = DC_STATUS_SUCCESS;
|
||||||
return DC_STATUS_UNSUPPORTED;
|
unsigned int lines = 0;
|
||||||
|
|
||||||
return iostream->vtable->get_lines (iostream, value);
|
if (iostream == NULL || iostream->vtable->get_lines == NULL) {
|
||||||
|
status = DC_STATUS_UNSUPPORTED;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = iostream->vtable->get_lines (iostream, &lines);
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (value)
|
||||||
|
*value = lines;
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_status_t
|
dc_status_t
|
||||||
dc_iostream_get_available (dc_iostream_t *iostream, size_t *value)
|
dc_iostream_get_available (dc_iostream_t *iostream, size_t *value)
|
||||||
{
|
{
|
||||||
if (iostream == NULL || iostream->vtable->get_available == NULL)
|
dc_status_t status = DC_STATUS_SUCCESS;
|
||||||
return DC_STATUS_UNSUPPORTED;
|
size_t available = 0;
|
||||||
|
|
||||||
return iostream->vtable->get_available (iostream, value);
|
if (iostream == NULL || iostream->vtable->get_available == NULL) {
|
||||||
|
status = DC_STATUS_UNSUPPORTED;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
status = iostream->vtable->get_available (iostream, &available);
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (value)
|
||||||
|
*value = available;
|
||||||
|
|
||||||
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
dc_status_t
|
dc_status_t
|
||||||
|
|||||||
Reference in New Issue
Block a user