Companion wizard fixes (#6536)

Fix string copies
This commit is contained in:
Neil Horne
2019-07-03 17:42:16 +02:00
committed by Bertrand Songis
parent 093025f444
commit 3ec6498155
2 changed files with 30 additions and 27 deletions
+27 -21
View File
@@ -44,14 +44,14 @@ WizMix::WizMix(const GeneralSettings & settings, unsigned int modelId, const Mod
originalModelData(modelData),
vehicle(NOVEHICLE)
{
strncpy(name, originalModelData.name, WIZ_MODEL_NAME_LENGTH);
memset(name, 0, sizeof(name));
strncpy(name, originalModelData.name, sizeof(name)-1);
}
void WizMix::maxMixSwitch(char *name, MixData &mix, int channel, int sw, int weight)
{
strncpy(mix.name, name, MIXDATA_NAME_LEN);
mix.name[MIXDATA_NAME_LEN] = '\0';
memset(mix.name, 0, sizeof(mix.name));
strncpy(mix.name, name, sizeof(mix.name)-1);
mix.destCh = channel;
mix.srcRaw = RawSource(SOURCE_TYPE_MAX);
mix.swtch = RawSwitch(SWITCH_TYPE_SWITCH, sw);
@@ -75,7 +75,7 @@ void WizMix::addMix(ModelData &model, Input input, int weight, int channel, int
}
else if (input==FLAPS_INPUT){
// There ought to be some kind of constants for switches somewhere...
maxMixSwitch((char *)"Flaps Up", model.mixData[mixIndex++], channel+1, isHorusOrTaranis ? SWITCH_SA0 :-SWITCH_ELE , weight); //Taranis-Horus SA-UP, 9X ELE-UP
maxMixSwitch((char *)"Flaps Up", model.mixData[mixIndex++], channel+1, isHorusOrTaranis ? SWITCH_SA0 :-SWITCH_ELE , weight); //Taranis-Horus SA-UP, 9X ELE-UP
maxMixSwitch((char *)"Flaps Dn", model.mixData[mixIndex++], channel+1, isHorusOrTaranis ? SWITCH_SA2 : SWITCH_ELE , -weight); //Taranis-Horus SA-DOWN, 9X ELE-DOWN
}
@@ -91,7 +91,6 @@ WizMix::operator ModelData()
int throttleChannel = -1;
ModelData model;
//ModelData model(originalModelData);
model.category = originalModelData.category;
model.used = true;
model.moduleData[0].modelId = modelId;
@@ -101,8 +100,8 @@ WizMix::operator ModelData()
int timerIndex = 0;
// Safe copy model name
strncpy(model.name, name, WIZ_MODEL_NAME_LENGTH);
model.name[WIZ_MODEL_NAME_LENGTH] = 0;
memset(model.name, 0, sizeof(model.name));
strncpy(model.name, name, sizeof(model.name)-1);
// Add the channel mixes
for (int i=0; i<WIZ_MAX_CHANNELS; i++ )
@@ -112,29 +111,36 @@ WizMix::operator ModelData()
addMix(model, ch.input1, ch.weight1, i, mixIndex);
addMix(model, ch.input2, ch.weight2, i, mixIndex);
if ((ch.input1 == THROTTLE_INPUT || ch.input2 == THROTTLE_INPUT) && options[THROTTLE_CUT_OPTION]) {
// Add the Throttle Cut option
MixData & mix = model.mixData[mixIndex++];
mix.destCh = i+1;
mix.srcRaw = SOURCE_TYPE_MAX;
mix.weight = -100;
mix.swtch.type = SWITCH_TYPE_SWITCH;
mix.swtch.index = IS_ARM(getCurrentBoard()) ? SWITCH_SF0 : SWITCH_THR;
mix.mltpx = MLTPX_REP;
strncpy(mix.name, "Cut", MIXDATA_NAME_LEN);
mix.name[MIXDATA_NAME_LEN] = '\0';
if (ch.input1 == THROTTLE_INPUT || ch.input2 == THROTTLE_INPUT) {
throttleChannel++;
if (options[THROTTLE_CUT_OPTION]) {
// Add the Throttle Cut option
MixData & mix = model.mixData[mixIndex++];
mix.destCh = i+1;
mix.srcRaw = SOURCE_TYPE_MAX;
mix.weight = -100;
mix.swtch.type = SWITCH_TYPE_SWITCH;
mix.swtch.index = IS_ARM(getCurrentBoard()) ? SWITCH_SF0 : SWITCH_THR;
mix.mltpx = MLTPX_REP;
memset(mix.name, 0, sizeof(mix.name));
strncpy(mix.name, "Cut", MIXDATA_NAME_LEN);
}
}
}
// Add the Flight Timer option
if (options[FLIGHT_TIMER_OPTION] ){
if (options[FLIGHT_TIMER_OPTION] && throttleChannel >= 0){
memset(model.timers[timerIndex].name, 0, sizeof(model.timers[timerIndex].name));
strncpy(model.timers[timerIndex].name, "Flt", sizeof(model.timers[timerIndex].name)-1);
model.timers[timerIndex].mode.type = SWITCH_TYPE_TIMER_MODE;
model.timers[timerIndex].mode.index = TMRMODE_THR_TRG;
timerIndex++;
}
// Add the Throttle Timer option
if (options[THROTTLE_TIMER_OPTION] && throttleChannel >=0){
if (options[THROTTLE_TIMER_OPTION] && throttleChannel >= 0){
memset(model.timers[timerIndex].name, 0, sizeof(model.timers[timerIndex].name));
strncpy(model.timers[timerIndex].name, "Thr", sizeof(model.timers[timerIndex].name)-1);
model.timers[timerIndex].mode.type = SWITCH_TYPE_TIMER_MODE;
model.timers[timerIndex].mode.index = TMRMODE_THR;
timerIndex++;
+3 -6
View File
@@ -306,8 +306,8 @@ bool ModelSelectionPage::validatePage()
QString newName(nameLineEdit->text());
newName = (newName.normalized(QString::NormalizationForm_D));
newName = newName.replace(QRegExp("[^ A-Za-z0-9_.-,\\s]"), "");
strncpy( wizDlg->mix.name, newName.toLatin1(), WIZ_MODEL_NAME_LENGTH);
wizDlg->mix.name[WIZ_MODEL_NAME_LENGTH] = 0;
memset(wizDlg->mix.name, 0, sizeof(wizDlg->mix.name));
strncpy( wizDlg->mix.name, newName.toLatin1(), sizeof(wizDlg->mix.name)-1);
if (multirotorRB->isChecked())
wizDlg->mix.vehicle = MULTICOPTER;
@@ -1053,7 +1053,7 @@ QString WizardPrinter::printChannel( Input input1, int weight1, Input input2, in
QString WizardPrinter::print()
{
QString str = tr("Model Name: ") + mix->name + "\n";
QString str = tr("Model Name: ") + QString::fromUtf8(mix->name) + "\n";
str += tr("Model Type: ") + vehicleName(mix->vehicle) + "\n";
str += tr("Options: ") + "[";
@@ -1075,6 +1075,3 @@ QString WizardPrinter::print()
}
return str;
}