Clean strlcpy arguments

This commit is contained in:
Léa Saviot
2018-10-15 15:56:12 +02:00
committed by EmilieNumworks
parent 06999e8e2e
commit 5d92f13c26
16 changed files with 69 additions and 84 deletions

View File

@@ -7,17 +7,18 @@ using namespace Poincare;
namespace Shared {
void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor * cursor, Function * function, char symbol) {
char buffer[k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
constexpr size_t bufferSize = k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);
char buffer[bufferSize];
const char * space = " ";
int spaceLength = strlen(space);
const char * legend = "0=";
int legendLength = strlen(legend);
int numberOfChar = 0;
strlcpy(buffer, legend, legendLength+1);
strlcpy(buffer, legend, bufferSize);
numberOfChar += legendLength;
buffer[0] = symbol;
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(cursor->x(), buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
strlcpy(buffer+numberOfChar, space, spaceLength+1);
strlcpy(buffer+numberOfChar, space, bufferSize - numberOfChar);
buffer[k_maxDigitLegendLength+2] = 0;
bannerView()->setLegendAtIndex(buffer, 0);
@@ -25,11 +26,11 @@ void FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(CurveViewCursor
legend = "0(x)=";
legendLength = strlen(legend);
numberOfChar += legendLength;
strlcpy(buffer, legend, legendLength+1);
strlcpy(buffer, legend, bufferSize);
buffer[2] = symbol;
buffer[0] = function->name()[0];
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(cursor->y(), buffer+legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
strlcpy(buffer+numberOfChar, space, spaceLength+1);
strlcpy(buffer+numberOfChar, space, bufferSize - numberOfChar);
buffer[k_maxDigitLegendLength+5] = 0;
bannerView()->setLegendAtIndex(buffer, 1);
}