From 7d7d099df0dd929f95de0f45a2b6b006545207c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20DEL=20NERO?= Date: Wed, 3 Jan 2024 00:53:11 +0100 Subject: [PATCH] unicode2charstring : Use bytes accesses instead of half word accesses to support unaligned addresses on pre ARMv7 CPUs. --- inc/mtp.h | 2 +- src/usbstring.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/inc/mtp.h b/inc/mtp.h index 376ddff..2c7db88 100644 --- a/inc/mtp.h +++ b/inc/mtp.h @@ -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 diff --git a/src/usbstring.c b/src/usbstring.c index 02f88c4..ec5a9ea 100644 --- a/src/usbstring.c +++ b/src/usbstring.c @@ -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