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

@@ -332,13 +332,14 @@ void ConsoleController::printText(const char * text, size_t length) {
void ConsoleController::autoImportScript(Script script, bool force) {
if (script.importationStatus() || force) {
// Create the command "from scriptName import *".
assert(strlen(k_importCommand1) + strlen(script.name()) - strlen(ScriptStore::k_scriptExtension) + strlen(k_importCommand2) + 1 <= k_maxImportCommandSize);
char command[k_maxImportCommandSize];
size_t currentChar = strlcpy(command, k_importCommand1, strlen(k_importCommand1)+1);
size_t currentChar = strlcpy(command, k_importCommand1, k_maxImportCommandSize);
const char * scriptName = script.name();
currentChar += strlcpy(command+currentChar, scriptName, strlen(scriptName)+1);
currentChar += strlcpy(command+currentChar, scriptName, k_maxImportCommandSize - currentChar);
// Remove the name extension ".py"
currentChar -= strlen(ScriptStore::k_scriptExtension);
currentChar += strlcpy(command+currentChar, k_importCommand2, strlen(k_importCommand2)+1);
currentChar += strlcpy(command+currentChar, k_importCommand2, k_maxImportCommandSize - currentChar);
runAndPrintForCommand(command);
}
if (force) {

View File

@@ -4,6 +4,8 @@
namespace Code {
static inline int min(int x, int y) { return (x<y ? x : y); }
ConsoleStore::ConsoleStore() :
m_history{0}
{
@@ -112,7 +114,7 @@ void ConsoleStore::push(const char marker, const char * text, size_t length) {
i = indexOfNullMarker();
}
m_history[i] = marker;
strlcpy(&m_history[i+1], text, textLength+1);
strlcpy(&m_history[i+1], text, min(k_historySize-(i+1),textLength+1));
m_history[i+1+textLength+1] = 0;
}

View File

@@ -17,17 +17,17 @@ bool GraphControllerHelper::privateMoveCursorHorizontally(Shared::CurveViewCurso
}
void GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(Shared::CurveViewCursor * cursor, CartesianFunction * function, TextFieldDelegateApp * app) {
char buffer[FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);
char buffer[bufferSize];
const char * space = " ";
int spaceLength = strlen(space);
const char * legend = "00(x)=";
int legendLength = strlen(legend);
int numberOfChar = strlcpy(buffer, legend, legendLength+1);
int numberOfChar = strlcpy(buffer, legend, bufferSize);
buffer[0] = function->name()[0];
buffer[1] = '\'';
double y = function->approximateDerivative(cursor->x(), app->localContext());
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits);
strlcpy(buffer+numberOfChar, space, spaceLength+1);
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(y, buffer + numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits);
strlcpy(buffer+numberOfChar, space, bufferSize - numberOfChar);
buffer[k_maxDigitLegendLength+6] = 0;
bannerView()->setLegendAtIndex(buffer, 2);
}

View File

@@ -21,18 +21,18 @@ const char * IntersectionGraphController::title() {
void IntersectionGraphController::reloadBannerView() {
m_bannerView->setNumberOfSubviews(2);
reloadBannerViewForCursorOnFunction(m_cursor, m_function, 'x');
char buffer[FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);
char buffer[bufferSize];
const char * space = " ";
int spaceLength = strlen(space);
const char * legend = "0(x)=0(x)=";
int legendLength = strlen(legend);
int numberOfChar = 0;
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += strlcpy(buffer, legend, bufferSize);
buffer[0] = m_function->name()[0];
buffer[5] = m_intersectedFunction->name()[0];
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(m_cursor->y(), buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
strlcpy(buffer+numberOfChar, space, spaceLength+1);
strlcpy(buffer+numberOfChar, space, bufferSize - numberOfChar);
buffer[FunctionBannerDelegate::k_maxDigitLegendLength+legendLength] = 0;
bannerView()->setLegendAtIndex(buffer, 1);
}

View File

@@ -42,17 +42,16 @@ void TangentGraphController::reloadBannerView() {
FunctionBannerDelegate::reloadBannerViewForCursorOnFunction(m_cursor, m_function, 'x');
TextFieldDelegateApp * myApp = (TextFieldDelegateApp *)app();
GraphControllerHelper::reloadDerivativeInBannerViewForCursorOnFunction(m_cursor, m_function, myApp);
char buffer[FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
constexpr size_t bufferSize = FunctionBannerDelegate::k_maxNumberOfCharacters+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);
char buffer[bufferSize];
const char * legend = "a=";
int legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
int legendLength = strlcpy(buffer, legend, bufferSize);
double y = m_function->approximateDerivative(m_cursor->x(), myApp->localContext());
PoincareHelpers::ConvertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
m_bannerView->setLegendAtIndex(buffer, 4);
legend = "b=";
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
legendLength = strlcpy(buffer, legend, bufferSize);
y = -y*m_cursor->x()+m_function->evaluateAtAbscissa(m_cursor->x(), myApp->localContext());
PoincareHelpers::ConvertFloatToText<double>(y, buffer + legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
m_bannerView->setLegendAtIndex(buffer, 5);

View File

@@ -40,26 +40,23 @@ void BatteryTestController::viewWillAppear() {
}
void BatteryTestController::updateBatteryState(float batteryLevel, bool batteryCharging) {
char bufferLevel[ContentView::k_maxNumberOfCharacters + PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
constexpr size_t bufferLevelSize = ContentView::k_maxNumberOfCharacters + PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);
char bufferLevel[bufferLevelSize];
const char * legend = "Battery level: ";
int legendLength = strlen(legend);
strlcpy(bufferLevel, legend, legendLength+1);
int legendLength = strlcpy(bufferLevel, legend, bufferLevelSize);
PrintFloat::convertFloatToText<float>(batteryLevel, bufferLevel+legendLength, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
m_view.batteryLevelTextView()->setText(bufferLevel);
char bufferCharging[ContentView::k_maxNumberOfCharacters + PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
constexpr size_t bufferChargingSize = ContentView::k_maxNumberOfCharacters + PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);
char bufferCharging[bufferChargingSize];
int numberOfChars = 0;
legend = "Battery charging: ";
legendLength = strlen(legend);
strlcpy(bufferCharging, legend, legendLength+1);
numberOfChars += legendLength;
numberOfChars += strlcpy(bufferCharging, legend, bufferChargingSize);
legend = "no";
if (batteryCharging) {
legend = "yes";
}
legendLength = strlen(legend);
strlcpy(bufferCharging+numberOfChars, legend, legendLength+1);
numberOfChars += legendLength;
numberOfChars += strlcpy(bufferCharging+numberOfChars, legend, bufferChargingSize);
bufferCharging[numberOfChars] = 0;
m_view.batteryChargingTextView()->setText(bufferCharging);
}

View File

@@ -274,11 +274,12 @@ void CalculationController::updateTitle() {
int currentChar = 0;
for (int index = 0; index < m_law->numberOfParameter(); index++) {
m_titleBuffer[currentChar++] = I18n::translate(m_law->parameterNameAtIndex(index))[0];
strlcpy(m_titleBuffer+currentChar, " = ", 4);
strlcpy(m_titleBuffer+currentChar, " = ", k_maxNumberOfTitleCharacters);
currentChar += 3;
char buffer[PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits)];
const size_t bufferSize = PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits);
char buffer[bufferSize];
PrintFloat::convertFloatToText<double>(m_law->parameterValueAtIndex(index), buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
strlcpy(m_titleBuffer+currentChar, buffer, strlen(buffer)+1);
strlcpy(m_titleBuffer+currentChar, buffer, bufferSize - currentChar);
currentChar += strlen(buffer);
m_titleBuffer[currentChar++] = ' ';
}

View File

@@ -92,32 +92,25 @@ void GraphController::reloadBannerView() {
}
// Set point equals: "P(...) ="
char buffer[k_maxNumberOfCharacters + PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
constexpr size_t bufferSize = k_maxNumberOfCharacters + PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);
char buffer[bufferSize];
int numberOfChar = 0;
const char * legend = " P(";
int legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += strlcpy(buffer, legend, bufferSize);
if (*m_selectedDotIndex == m_store->numberOfPairsOfSeries(*m_selectedSeriesIndex)) {
legend = I18n::translate(I18n::Message::MeanDot);
legendLength = strlen(legend);
strlcpy(buffer+numberOfChar, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize - numberOfChar);
} else if (*m_selectedDotIndex < 0) {
legend = I18n::translate(I18n::Message::Reg);
legendLength = strlen(legend);
strlcpy(buffer+numberOfChar, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += strlcpy(buffer+numberOfChar, legend, bufferSize - numberOfChar);
} else {
numberOfChar += PrintFloat::convertFloatToText<float>(std::round((float)*m_selectedDotIndex+1.0f), buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::ShortNumberOfSignificantDigits), Constant::ShortNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
}
legend = ") ";
legendLength = strlen(legend);
strlcpy(buffer+numberOfChar, legend, legendLength+1);
strlcpy(buffer+numberOfChar, legend, bufferSize - numberOfChar);
buffer[k_maxLegendLength] = 0;
m_bannerView.setLegendAtIndex(buffer, 0);
// Set "x=..." or "xmean=..."
numberOfChar = 0;
legend = "x=";
@@ -128,9 +121,7 @@ void GraphController::reloadBannerView() {
legend = legX;
x = m_store->meanOfColumn(*m_selectedSeriesIndex, 0);
}
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += strlcpy(buffer, legend, bufferSize);
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(x, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
for (int i = numberOfChar; i < k_maxLegendLength; i++) {
buffer[numberOfChar++] = ' ';
@@ -147,9 +138,7 @@ void GraphController::reloadBannerView() {
legend = legY;
y = m_store->meanOfColumn(*m_selectedSeriesIndex, 1);
}
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += strlcpy(buffer, legend, bufferSize);
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(y, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::MediumNumberOfSignificantDigits), Constant::MediumNumberOfSignificantDigits);
for (int i = numberOfChar; i < k_maxLegendLength; i++) {
buffer[numberOfChar++] = ' ';
@@ -194,9 +183,7 @@ void GraphController::reloadBannerView() {
numberOfChar = 0;
char leg[] = {' ', coefficientName, '=', 0};
legend = leg;
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += strlcpy(buffer, legend, bufferSize);
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(coefficients[i], buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
buffer[k_maxLegendLength] = 0;
m_bannerView.setLegendAtIndex(buffer, 4 + i);
@@ -208,9 +195,7 @@ void GraphController::reloadBannerView() {
numberOfChar = 0;
legend = " r=";
double r = m_store->correlationCoefficient(*m_selectedSeriesIndex);
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += strlcpy(buffer, legend, bufferSize);
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(r, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
buffer[k_maxLegendLength+10] = 0;
m_bannerView.setLegendAtIndex(buffer, 6);
@@ -219,9 +204,7 @@ void GraphController::reloadBannerView() {
numberOfChar = 0;
legend = " r2=";
double r2 = m_store->squaredCorrelationCoefficient(*m_selectedSeriesIndex);
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
numberOfChar += legendLength;
numberOfChar += strlcpy(buffer, legend, bufferSize);
numberOfChar += PoincareHelpers::ConvertFloatToText<double>(r2, buffer+numberOfChar, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
buffer[k_maxLegendLength] = 0;
m_bannerView.setLegendAtIndex(buffer, 7);

View File

@@ -29,10 +29,11 @@ Sequence::Sequence(const char * text, KDColor color) :
}
uint32_t Sequence::checksum() {
char data[k_dataLengthInBytes/sizeof(char)] = {};
strlcpy(data, text(), TextField::maxBufferSize());
strlcpy(data+TextField::maxBufferSize(), firstInitialConditionText(), TextField::maxBufferSize());
strlcpy(data+2*TextField::maxBufferSize(), secondInitialConditionText(), TextField::maxBufferSize());
constexpr size_t dataSize = k_dataLengthInBytes/sizeof(char);
char data[dataSize] = {};
strlcpy(data, text(), dataSize);
strlcpy(data+TextField::maxBufferSize(), firstInitialConditionText(), dataSize - TextField::maxBufferSize());
strlcpy(data+2*TextField::maxBufferSize(), secondInitialConditionText(), dataSize - 2*TextField::maxBufferSize());
int * intAdress = (int *)(&data[3*TextField::maxBufferSize()]);
*intAdress = m_initialRank;
data[k_dataLengthInBytes-3] = (char)m_type;

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);
}

View File

@@ -243,7 +243,8 @@ void SumGraphController::LegendView::setSumSymbol(Step step, double start, doubl
EmptyLayout(EmptyLayoutNode::Color::Yellow, false, KDFont::SmallFont, false));
} else {
m_sumLayout = LayoutHelper::String(sigma, sizeof(sigma));
char buffer[2+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)];
constexpr size_t bufferSize = 2+PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits);
char buffer[bufferSize];
PrintFloat::convertFloatToText<double>(start, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
Layout start = LayoutHelper::String(buffer, strlen(buffer), KDFont::SmallFont);
PrintFloat::convertFloatToText<double>(end, buffer, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits, Preferences::PrintFloatMode::Decimal);
@@ -252,7 +253,7 @@ void SumGraphController::LegendView::setSumSymbol(Step step, double start, doubl
LayoutHelper::String(sigma, sizeof(sigma)),
start,
end);
strlcpy(buffer, "= ", 3);
strlcpy(buffer, "= ", bufferSize);
PoincareHelpers::ConvertFloatToText<double>(result, buffer+2, PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits), Constant::LargeNumberOfSignificantDigits);
m_sumLayout = HorizontalLayout(
m_sumLayout,

View File

@@ -88,13 +88,14 @@ void HistogramController::reloadBannerView() {
if (selectedSeriesIndex() < 0) {
return;
}
char buffer[k_maxNumberOfCharacters+ PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)*2];
const size_t bufferSize = k_maxNumberOfCharacters+ PrintFloat::bufferSizeForFloatsWithPrecision(Constant::LargeNumberOfSignificantDigits)*2;
char buffer[bufferSize];
int numberOfChar = 0;
// Add Interval Data
const char * legend = " [";
int legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
strlcpy(buffer, legend, bufferSize);
numberOfChar += legendLength;
// Add lower bound
@@ -123,7 +124,7 @@ void HistogramController::reloadBannerView() {
numberOfChar = 0;
legend = ": ";
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
strlcpy(buffer, legend, bufferSize);
numberOfChar += legendLength;
double size = 0;
if (selectedSeriesIndex() >= 0) {
@@ -141,7 +142,7 @@ void HistogramController::reloadBannerView() {
numberOfChar = 0;
legend = ": ";
legendLength = strlen(legend);
strlcpy(buffer, legend, legendLength+1);
strlcpy(buffer, legend, bufferSize);
numberOfChar += legendLength;
if (selectedSeriesIndex() >= 0) {
double frequency = size/m_store->sumOfOccurrences(selectedSeriesIndex());

View File

@@ -82,18 +82,16 @@ void TitleBarView::layoutSubviews() {
}
void TitleBarView::refreshPreferences() {
char buffer[13];
constexpr size_t bufferSize = 13;
char buffer[bufferSize];
int numberOfChar = 0;
if (Preferences::sharedPreferences()->displayMode() == Preferences::PrintFloatMode::Scientific) {
strlcpy(buffer, I18n::translate(I18n::Message::Sci), strlen(I18n::translate(I18n::Message::Sci))+1);
numberOfChar += strlen(I18n::translate(I18n::Message::Sci));
numberOfChar += strlcpy(buffer, I18n::translate(I18n::Message::Sci), bufferSize);
}
if (Preferences::sharedPreferences()->angleUnit() == Preferences::AngleUnit::Radian) {
strlcpy(buffer+numberOfChar, I18n::translate(I18n::Message::Rad), strlen(I18n::translate(I18n::Message::Rad))+1);
numberOfChar += strlen(I18n::translate(I18n::Message::Rad));
numberOfChar += strlcpy(buffer+numberOfChar, I18n::translate(I18n::Message::Rad), bufferSize - numberOfChar);
} else {
strlcpy(buffer+numberOfChar, I18n::translate(I18n::Message::Deg), strlen(I18n::translate(I18n::Message::Sci))+1);
numberOfChar += strlen(I18n::translate(I18n::Message::Deg));
numberOfChar += strlcpy(buffer+numberOfChar, I18n::translate(I18n::Message::Deg), bufferSize - numberOfChar);
}
buffer[numberOfChar] = 0;
m_preferenceView.setText(buffer);

View File

@@ -23,6 +23,6 @@ void BufferTextView::appendText(const char * text) {
size_t previousTextLength = strlen(m_buffer);
size_t argTextLength = strlen(text);
if (previousTextLength + argTextLength + 1 < k_maxNumberOfChar) {
strlcpy(&m_buffer[previousTextLength], text, argTextLength + 1);
strlcpy(&m_buffer[previousTextLength], text, k_maxNumberOfChar - previousTextLength);
}
}

View File

@@ -99,7 +99,7 @@ bool TextField::ContentView::insertTextAtLocation(const char * text, int locatio
for (int k = m_currentDraftTextLength; k >= location && k >= 0; k--) {
m_draftTextBuffer[k+textSize] = m_draftTextBuffer[k];
}
strlcpy(&m_draftTextBuffer[location], text, textSize);
strlcpy(&m_draftTextBuffer[location], text, m_textBufferSize-location);
if (location+textSize > 0) {
m_draftTextBuffer[location+textSize-1] = text[textSize-1];
}

View File

@@ -122,7 +122,7 @@ int SymbolNode::serialize(char * buffer, int bufferSize, Preferences::PrintFloat
return -1;
}
if (bufferSize == 1) {
buffer[bufferSize-1] = 0;
buffer[0] = 0;
return 0;
}
/* Special cases for all special symbols */