Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tidy up endian swap code #634

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading