Skip to content

Commit

Permalink
Tidy up endian swap code
Browse files Browse the repository at this point in the history
Fix missing trailing character on odd model lengths
Remove unnecessary +1 from length calculation (strlen)
Remove debug nwipe_log message
  • Loading branch information
PartialVolume committed Jan 2, 2025
1 parent 523ebc4 commit 6e4ca14
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/miscellaneous.c
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,7 @@ void fix_endian_model_names( char* model )
char* model_lower_case;
int swap_endian_flag = 0;

length = strlen( model ) + 1;
nwipe_log( NWIPE_LOG_INFO, " length = %i", length );
length = strlen( model );

tmp_string = calloc( length + 1, 1 );
model_lower_case = calloc( length + 1, 1 );
Expand All @@ -645,6 +644,7 @@ void fix_endian_model_names( char* model )
/* "ASSMNU G" = "SAMSUNG ", tested against model Samsung HM160HC so that
* "ASSMNU G MH61H0 C" becomes "SAMSUNG HM160HC ")
*/

if( !( strncmp( model_lower_case, "assmnu g", 8 ) ) )
{
swap_endian_flag = 1;
Expand Down Expand Up @@ -694,13 +694,16 @@ void fix_endian_model_names( char* model )
{
while( model[idx] != 0 && idx < length )
{
tmp_string[idx2 + 1] = model[idx];
if( model[idx + 1] != 0 )
{
/* Swap the bytes */
tmp_string[idx2 + 1] = model[idx];
tmp_string[idx2] = model[idx + 1];
}
else
{
/* Copy the last odd byte and exit while loop */
tmp_string[idx2] = model[idx];
break;
}

Expand Down

0 comments on commit 6e4ca14

Please sign in to comment.