Fixed more zchar / string copy errors

Resolves #224
This commit is contained in:
Raphael Coeffic
2021-06-16 18:00:42 +02:00
parent da8e1022a0
commit d10563d08b
4 changed files with 13 additions and 12 deletions
+1 -1
View File
@@ -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) {
+2 -1
View File
@@ -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;
}
+1 -1
View File
@@ -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 {
+9 -9
View File
@@ -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 {