Skip to content
Snippets Groups Projects
Commit f9acb79d authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Fix unaligned memory accesses as reported by ASan

e.g. runtime error: store to misaligned address 0x7ffec33195e3 for type
'short int', which requires 2 byte alignment

These aren't a problem for x86, but could be a problem for some other CPU
architectures that don't support unaligned access. I didn't use memcpy() to
resolve this (though that would've worked) to make this change endian agnostic.
parent 999c097c
No related branches found
No related tags found
1 merge request!463MRC mods by Codefenix (2024-10-20)
...@@ -565,8 +565,8 @@ uchar* arstr(ushort* count, const char* str, scfg_t* cfg, uchar* ar_buf) ...@@ -565,8 +565,8 @@ uchar* arstr(ushort* count, const char* str, scfg_t* cfg, uchar* ar_buf)
p=strchr(str+i,':'); p=strchr(str+i,':');
if(p) if(p)
n+=atoi(p+1); n+=atoi(p+1);
*((short *)(ar+j))=n; ar[j++] = n & 0xff;
j+=2; ar[j++] = (n >> 8) & 0xff;
while(IS_DIGIT(str[i+1]) || str[i+1]==':') i++; while(IS_DIGIT(str[i+1]) || str[i+1]==':') i++;
continue; continue;
} }
...@@ -606,16 +606,16 @@ uchar* arstr(ushort* count, const char* str, scfg_t* cfg, uchar* ar_buf) ...@@ -606,16 +606,16 @@ uchar* arstr(ushort* count, const char* str, scfg_t* cfg, uchar* ar_buf)
case AR_DLS: case AR_DLS:
case AR_DLK: case AR_DLK:
case AR_DLM: case AR_DLM:
*((short *)(ar+j))=n; ar[j++] = n & 0xff;
j+=sizeof(short); ar[j++] = (n >> 8) & 0xff;
break; break;
case AR_GROUP: case AR_GROUP:
case AR_LIB: case AR_LIB:
case AR_DIR: case AR_DIR:
case AR_SUB: case AR_SUB:
if(n) n--; /* convert to 0 base */ if(n > 0) n--; /* convert to 0 base */
*((short *)(ar+j))=n; ar[j++] = n & 0xff;
j+=2; ar[j++] = (n >> 8) & 0xff;
break; break;
default: /* invalid numeric AR type */ default: /* invalid numeric AR type */
j--; j--;
...@@ -663,8 +663,8 @@ uchar* arstr(ushort* count, const char* str, scfg_t* cfg, uchar* ar_buf) ...@@ -663,8 +663,8 @@ uchar* arstr(ushort* count, const char* str, scfg_t* cfg, uchar* ar_buf)
if(!strnicmp(str+i,cfg->sub[n]->code,strlen(cfg->sub[n]->code))) if(!strnicmp(str+i,cfg->sub[n]->code,strlen(cfg->sub[n]->code)))
break; break;
if(n<(uint)cfg->total_subs) { if(n<(uint)cfg->total_subs) {
*((short *)(ar+j))=n; ar[j++] = n & 0xff;
j+=2; ar[j++] = (n >> 8) & 0xff;
} }
else /* Unknown sub-board */ else /* Unknown sub-board */
j--; j--;
...@@ -675,8 +675,8 @@ uchar* arstr(ushort* count, const char* str, scfg_t* cfg, uchar* ar_buf) ...@@ -675,8 +675,8 @@ uchar* arstr(ushort* count, const char* str, scfg_t* cfg, uchar* ar_buf)
if(!strnicmp(str+i,cfg->dir[n]->code,strlen(cfg->dir[n]->code))) if(!strnicmp(str+i,cfg->dir[n]->code,strlen(cfg->dir[n]->code)))
break; break;
if(n<(uint)cfg->total_dirs) { if(n<(uint)cfg->total_dirs) {
*((short *)(ar+j))=n; ar[j++] = n & 0xff;
j+=2; ar[j++] = (n >> 8) & 0xff;
} }
else /* Unknown directory */ else /* Unknown directory */
j--; j--;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment