From d10563d08b2e7c9cbe3af35ebe298ed536daf5e2 Mon Sep 17 00:00:00 2001 From: Raphael Coeffic Date: Wed, 16 Jun 2021 17:43:27 +0200 Subject: [PATCH] Fixed more zchar / string copy errors Resolves #224 --- radio/src/logs.cpp | 2 +- radio/src/lua/api_general.cpp | 3 ++- radio/src/storage/eeprom_common.cpp | 2 +- radio/src/strhelpers.cpp | 18 +++++++++--------- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/radio/src/logs.cpp b/radio/src/logs.cpp index bd8767d52..b1003b441 100644 --- a/radio/src/logs.cpp +++ b/radio/src/logs.cpp @@ -143,7 +143,7 @@ void writeHeader() TelemetrySensor & sensor = g_model.telemetrySensors[i]; if (sensor.logs) { memset(label, 0, sizeof(label)); - zchar2str(label, sensor.label, TELEM_LABEL_LEN); + strncpy(label, sensor.label, TELEM_LABEL_LEN); uint8_t unit = sensor.unit; if (unit == UNIT_CELLS ) unit = UNIT_VOLTS; if (UNIT_RAW < unit && unit < UNIT_FIRST_VIRTUAL) { diff --git a/radio/src/lua/api_general.cpp b/radio/src/lua/api_general.cpp index 47eced18b..f3654af3d 100644 --- a/radio/src/lua/api_general.cpp +++ b/radio/src/lua/api_general.cpp @@ -919,7 +919,8 @@ static int luaGetFlightMode(lua_State * L) } lua_pushnumber(L, mode); char name[sizeof(g_model.flightModeData[0].name)+1]; - zchar2str(name, g_model.flightModeData[mode].name, sizeof(g_model.flightModeData[0].name)); + strncpy(name, g_model.flightModeData[mode].name, sizeof(g_model.flightModeData[0].name)); + name[sizeof(g_model.flightModeData[0].name)] = '\0'; lua_pushstring(L, name); return 2; } diff --git a/radio/src/storage/eeprom_common.cpp b/radio/src/storage/eeprom_common.cpp index dffab63fb..839feedb3 100644 --- a/radio/src/storage/eeprom_common.cpp +++ b/radio/src/storage/eeprom_common.cpp @@ -169,7 +169,7 @@ void checkModelIdUnique(uint8_t index, uint8_t module) name = strAppendUnsigned(name+strlen(name), i + 1, 2); } else { - name += zchar2str(name, modelHeaders[i].name, LEN_MODEL_NAME); + name = strAppend(name, modelHeaders[i].name, LEN_MODEL_NAME); } } else { diff --git a/radio/src/strhelpers.cpp b/radio/src/strhelpers.cpp index 7777b7335..48bb7a8af 100644 --- a/radio/src/strhelpers.cpp +++ b/radio/src/strhelpers.cpp @@ -312,9 +312,8 @@ char * getSwitchWarningString(char * dest, swsrc_t idx) char * getSwitchName(char * dest, swsrc_t idx) { div_t swinfo = switchInfo(idx); - if (ZEXIST(g_eeGeneral.switchNames[swinfo.quot])) { - dest += zchar2str(dest, g_eeGeneral.switchNames[swinfo.quot], LEN_SWITCH_NAME); - // TODO tous zchar2str + if (g_eeGeneral.switchNames[swinfo.quot][0] != '\0') { + dest = strAppend(dest, g_eeGeneral.switchNames[swinfo.quot], LEN_SWITCH_NAME); } else { *dest++ = 'S'; @@ -404,7 +403,8 @@ char * getSwitchPositionName(char * dest, swsrc_t idx) } #endif else { - zchar2str(s, g_model.telemetrySensors[idx-SWSRC_FIRST_SENSOR].label, TELEM_LABEL_LEN); + strncpy(s, g_model.telemetrySensors[idx-SWSRC_FIRST_SENSOR].label, TELEM_LABEL_LEN); + s[TELEM_LABEL_LEN] = '\0'; } return dest; @@ -419,7 +419,7 @@ char * getSourceString(char * dest, mixsrc_t idx) idx -= MIXSRC_FIRST_INPUT; *dest = CHAR_INPUT; if (strlen(g_model.inputNames[idx])) { - memset(dest + 1, 0, LEN_INPUT_NAME); + memset(dest + 1, 0, LEN_INPUT_NAME+1); strncpy(dest + 1, g_model.inputNames[idx], LEN_INPUT_NAME); } else { @@ -473,8 +473,8 @@ char * getSourceString(char * dest, mixsrc_t idx) } else if (idx <= MIXSRC_LAST_SWITCH) { idx -= MIXSRC_FIRST_SWITCH; - if (ZEXIST(g_eeGeneral.switchNames[idx])) { - zchar2str(dest, g_eeGeneral.switchNames[idx], LEN_SWITCH_NAME); + if (g_eeGeneral.switchNames[idx][0] != '\0') { + strncpy(dest, g_eeGeneral.switchNames[idx], LEN_SWITCH_NAME); dest[LEN_SWITCH_NAME] = '\0'; } else { @@ -497,8 +497,8 @@ char * getSourceString(char * dest, mixsrc_t idx) getStringAtIndex(dest, STR_VSRCRAW, idx-MIXSRC_Rud+1-MAX_LOGICAL_SWITCHES-MAX_TRAINER_CHANNELS-MAX_OUTPUT_CHANNELS-MAX_GVARS); } else if (idx <= MIXSRC_LAST_TIMER) { - if(ZEXIST(g_model.timers[idx-MIXSRC_FIRST_TIMER].name)) { - zchar2str(dest,g_model.timers[idx-MIXSRC_FIRST_TIMER].name, LEN_TIMER_NAME); + if(g_model.timers[idx-MIXSRC_FIRST_TIMER].name[0] != '\0') { + strncpy(dest,g_model.timers[idx-MIXSRC_FIRST_TIMER].name, LEN_TIMER_NAME); dest[LEN_TIMER_NAME] = '\0'; } else {