From 0ac534bdc67d4f0ca40c49ccc1a9ecba7710711c Mon Sep 17 00:00:00 2001 From: roberChen Date: Thu, 30 Dec 2021 02:05:35 +0800 Subject: [PATCH] fix: out of bound error in string when preview module FUNKTION, LABEL, PLAY string out of bound error --- src/FUNKTION.cpp | 5 ++--- src/LABEL.cpp | 5 ++--- src/PLAY.cpp | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/FUNKTION.cpp b/src/FUNKTION.cpp index 6552b94..07a798d 100644 --- a/src/FUNKTION.cpp +++ b/src/FUNKTION.cpp @@ -122,9 +122,8 @@ struct FUNKTIONDisplay : TransparentWidget { void drawLayer(const DrawArgs &args, int layer) override { if (layer ==1) { shared_ptr font = APP->window->loadFont(asset::plugin(pluginInstance, "res/LEDCalculator.ttf")); -std::string fD= module ? module->fctDesc : "sin"; - std::string to_display = ""; - for (int i=0; i<14; i++) to_display = to_display + fD[i]; +std::string to_display= module ? module->fctDesc : "sin"; + to_display.resize(14); nvgFontSize(args.vg, 24); nvgFontFaceId(args.vg, font->handle); nvgTextLetterSpacing(args.vg, 0); diff --git a/src/LABEL.cpp b/src/LABEL.cpp index c6865cb..29f4013 100644 --- a/src/LABEL.cpp +++ b/src/LABEL.cpp @@ -71,9 +71,8 @@ struct LABELDisplay : TransparentWidget { void drawLayer(const DrawArgs &args, int layer) override { if (layer ==1) { shared_ptr font = APP->window->loadFont(asset::plugin(pluginInstance, "res/LEDCalculator.ttf")); -std::string fD= module ? module->fileDesc : "Right click to write"; - std::string to_display = ""; - for (int i=0; i<20; i++) to_display = to_display + fD[i]; +std::string to_display= module ? module->fileDesc : "Right click to write"; + to_display.resize(20); nvgFontSize(args.vg, 24); nvgFontFaceId(args.vg, font->handle); nvgTextLetterSpacing(args.vg, 0); diff --git a/src/PLAY.cpp b/src/PLAY.cpp index aea451e..23f2030 100644 --- a/src/PLAY.cpp +++ b/src/PLAY.cpp @@ -249,9 +249,8 @@ struct PLAYDisplay : TransparentWidget { void drawLayer(const DrawArgs &args, int layer) override { if (layer ==1) { shared_ptr font = APP->window->loadFont(asset::plugin(pluginInstance, "res/LEDCalculator.ttf")); -std::string fD= module ? module->fileDesc : "load sample"; - std::string to_display = ""; - for (int i=0; i<14; i++) to_display = to_display + fD[i]; +std::string to_display= module ? module->fileDesc : "load sample "; + to_display.resize(14); nvgFontSize(args.vg, 24); nvgFontFaceId(args.vg, font->handle); nvgTextLetterSpacing(args.vg, 0);