fix(yaml): Potential unaligned access when reading/writing switch warning positions (#3232)
It IS unaligned for the X9E
This commit is contained in:
@@ -952,7 +952,6 @@ static void r_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs,
|
|||||||
const char* val, uint8_t val_len)
|
const char* val, uint8_t val_len)
|
||||||
{
|
{
|
||||||
data += (bitoffs >> 3UL);
|
data += (bitoffs >> 3UL);
|
||||||
swarnstate_t& swtchWarn = *(swarnstate_t*)data;
|
|
||||||
|
|
||||||
// Read from string like 'AdBuC-':
|
// Read from string like 'AdBuC-':
|
||||||
//
|
//
|
||||||
@@ -963,12 +962,13 @@ static void r_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs,
|
|||||||
//
|
//
|
||||||
// -> switches not in the list shall not be checked
|
// -> switches not in the list shall not be checked
|
||||||
//
|
//
|
||||||
swtchWarn = 0;
|
swarnstate_t swtchWarn = 0;
|
||||||
|
|
||||||
while (val_len--) {
|
while (val_len--) {
|
||||||
signed swtch = getRawSwitchIdx(*(val++));
|
signed swtch = getRawSwitchIdx(*(val++));
|
||||||
if (swtch < 0) break;
|
if (swtch < 0) break;
|
||||||
|
|
||||||
unsigned state = 0;
|
swarnstate_t state = 0;
|
||||||
switch (*(val++)) {
|
switch (*(val++)) {
|
||||||
case 'u':
|
case 'u':
|
||||||
state = 1;
|
state = 1;
|
||||||
@@ -987,13 +987,17 @@ static void r_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs,
|
|||||||
// 3 bits per switch
|
// 3 bits per switch
|
||||||
swtchWarn |= (state << (3 * swtch));
|
swtchWarn |= (state << (3 * swtch));
|
||||||
}
|
}
|
||||||
|
memcpy(data, &swtchWarn, sizeof(swtchWarn));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool w_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs,
|
static bool w_swtchWarn(void* user, uint8_t* data, uint32_t bitoffs,
|
||||||
yaml_writer_func wf, void* opaque)
|
yaml_writer_func wf, void* opaque)
|
||||||
{
|
{
|
||||||
data += (bitoffs >> 3UL);
|
data += (bitoffs >> 3UL);
|
||||||
swarnstate_t states = *(swarnstate_t*)data;
|
|
||||||
|
swarnstate_t states;
|
||||||
|
memcpy(&states, data, sizeof(states));
|
||||||
|
|
||||||
for (int i = 0; i < NUM_SWITCHES; i++) {
|
for (int i = 0; i < NUM_SWITCHES; i++) {
|
||||||
// TODO: SWITCH_EXISTS() uses the g_eeGeneral stucture, which might not be
|
// TODO: SWITCH_EXISTS() uses the g_eeGeneral stucture, which might not be
|
||||||
|
|||||||
Reference in New Issue
Block a user