Skip to content

Commit

Permalink
unicode2charstring : Use bytes accesses instead of half word accesses…
Browse files Browse the repository at this point in the history
… to support unaligned addresses on pre ARMv7 CPUs.
  • Loading branch information
jfdelnero committed Jan 2, 2024
1 parent 299f25e commit 7d7d099
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion inc/mtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,6 @@ int build_response(mtp_ctx * ctx, uint32_t tx_id, uint16_t type, uint16_t status
int check_and_send_USB_ZLP(mtp_ctx * ctx , int size);
int parse_incomming_dataset(mtp_ctx * ctx,void * datain,int size,uint32_t * newhandle, uint32_t parent_handle, uint32_t storage_id);

#define APP_VERSION "v1.6.5"
#define APP_VERSION "v1.6.6"

#endif
9 changes: 7 additions & 2 deletions src/usbstring.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,17 @@ int unicode2charstring(char * str, uint16_t * unicodestr, int maxstrsize)
int i,j,ret;
int chunksize;
char tmpstr[8];
unsigned char * byte_access;

// Use bytes accesses instead of half word accesses to support unaligned addresses on pre ARMv7 CPUs.
byte_access = (unsigned char *)unicodestr;

ret = 0;
i = 0;
while( *unicodestr )
while( byte_access[0] || byte_access[1] )
{
chunksize = utf8_encode((char*)&tmpstr, *unicodestr++);
chunksize = utf8_encode( (char*)&tmpstr, ( ((uint16_t)byte_access[1]) << 8 ) | byte_access[0] );
byte_access += 2;

if(!chunksize)
{ // Error -> default character
Expand Down

0 comments on commit 7d7d099

Please sign in to comment.