Skip to content
Snippets Groups Projects
Commit 10a6fc63 authored by Alexandre Janniaux's avatar Alexandre Janniaux Committed by Felix Paul Kühne
Browse files

ts: arib: use early return

It simplifies the handling of the different error cases, and ensure
every case is ending with a return. The 3: case was not ending with a
return before, leading to potential (harmless currently) fallthrough to
the default case.

In addition, between one to two indentation level is saved, and the
further the reader go through the function, the less guarantee there is
to check before usage. For instance, after the beginning, p_dr is set to
be valid without needing to check if we use it in the correct condition
or not. Thus, even the error handling where breaks fall-through is
simplified to just clean up existing objects.
parent d747ad50
No related branches found
No related tags found
1 merge request!2147ts: arib: use early return
Pipeline #236573 passed with stage
in 15 minutes and 6 seconds
......@@ -172,42 +172,39 @@ ts_arib_logo_dr_t * ts_arib_logo_dr_Decode( const uint8_t *p_data, size_t i_data
return NULL;
ts_arib_logo_dr_t *p_dr = calloc( 1, sizeof(*p_dr) );
if( p_dr )
if( unlikely( p_dr == NULL ) )
return NULL;
p_dr->i_logo_version = p_data[0];
switch( p_data[0] )
{
p_dr->i_logo_version = p_data[0];
switch( p_data[0] )
{
case 1:
if( i_data == 7 )
{
p_dr->i_logo_id = ((p_data[1] & 0x01) << 8) | p_data[2];
p_dr->i_logo_version = ((p_data[3] & 0x0F) << 8) | p_data[4];
p_dr->i_download_data_id = (p_data[5] << 8) | p_data[6];
return p_dr;
}
case 1:
if( i_data != 7 )
break;
case 2:
if( i_data == 3 )
{
p_dr->i_logo_id = ((p_data[1] & 0x01) << 8) | p_data[2];
return p_dr;
}
p_dr->i_logo_id = ((p_data[1] & 0x01) << 8) | p_data[2];
p_dr->i_logo_version = ((p_data[3] & 0x0F) << 8) | p_data[4];
p_dr->i_download_data_id = (p_data[5] << 8) | p_data[6];
return p_dr;
case 2:
if( i_data != 3 )
break;
case 3:
if( i_data > 2 )
{
p_dr->p_logo_char = malloc( i_data - 1 );
if( p_dr->p_logo_char )
{
p_dr->i_logo_char = i_data - 1;
memcpy( p_dr->p_logo_char, &p_data[1], p_dr->i_logo_char );
return p_dr;
}
}
default:
p_dr->i_logo_id = ((p_data[1] & 0x01) << 8) | p_data[2];
return p_dr;
case 3:
if( i_data <= 2 )
break;
}
ts_arib_logo_dr_Delete( p_dr );
p_dr->p_logo_char = malloc( i_data - 1 );
if( unlikely( p_dr->p_logo_char == NULL ) )
break;
p_dr->i_logo_char = i_data - 1;
memcpy( p_dr->p_logo_char, &p_data[1], p_dr->i_logo_char );
return p_dr;
default:
break;
}
ts_arib_logo_dr_Delete( p_dr );
return NULL;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment