diff --git a/companion/src/wizarddata.cpp b/companion/src/wizarddata.cpp index 70a246af6..f544ee4b0 100644 --- a/companion/src/wizarddata.cpp +++ b/companion/src/wizarddata.cpp @@ -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= 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++; diff --git a/companion/src/wizarddialog.cpp b/companion/src/wizarddialog.cpp index e681cfc6e..189167c97 100644 --- a/companion/src/wizarddialog.cpp +++ b/companion/src/wizarddialog.cpp @@ -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; } - - -