[Scummvm-git-logs] scummvm master -> c73fac1cda2f9f8752e8607c09a679f0fbd13c02

lephilousophe noreply at scummvm.org
Sun Nov 6 16:27:26 UTC 2022


This automated email contains information about 5 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
3abe41aa1b AGI: Fix strncpy usage
49d53bb58e GLK: Fix strncpy usage
f816efdbb0 MUTATIONOFJB: Fix strncpy usage
c236ce82e6 SAGA: Fix strncpy usage
c73fac1cda GUI: Fix strncpy usage


Commit: 3abe41aa1bfbc767c32cc4651bbad185dbbc093f
    https://github.com/scummvm/scummvm/commit/3abe41aa1bfbc767c32cc4651bbad185dbbc093f
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-06T17:27:21+01:00

Commit Message:
AGI: Fix strncpy usage

Changed paths:
    engines/agi/text.cpp


diff --git a/engines/agi/text.cpp b/engines/agi/text.cpp
index 26c4242c2c8..d0eb753514f 100644
--- a/engines/agi/text.cpp
+++ b/engines/agi/text.cpp
@@ -889,7 +889,7 @@ void TextMgr::promptCommandWindow(bool recallLastCommand, uint16 newKey) {
 	if (_systemUI->askForCommand(commandText)) {
 		if (commandText.size()) {
 			// Something actually was entered?
-			strncpy((char *)&_prompt, commandText.c_str(), sizeof(_prompt));
+			Common::strcpy_s((char *)_prompt, sizeof(_prompt), commandText.c_str());
 			promptRememberForAutoComplete(true);
 			memcpy(&_promptPrevious, &_prompt, sizeof(_prompt));
 			// parse text


Commit: 49d53bb58e5f245bdb688ea2831685ea5e20438d
    https://github.com/scummvm/scummvm/commit/49d53bb58e5f245bdb688ea2831685ea5e20438d
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-06T17:27:21+01:00

Commit Message:
GLK: Fix strncpy usage

Changed paths:
    engines/glk/jacl/interpreter.cpp
    engines/glk/jacl/parser.cpp
    engines/glk/level9/os_glk.cpp
    engines/glk/tads/tads2/vocabulary_parser.cpp


diff --git a/engines/glk/jacl/interpreter.cpp b/engines/glk/jacl/interpreter.cpp
index 47dba1460d9..24a44dd4002 100644
--- a/engines/glk/jacl/interpreter.cpp
+++ b/engines/glk/jacl/interpreter.cpp
@@ -331,8 +331,7 @@ void cb1(void *s, size_t i, void *not_used) {
 		//write_text("Resolved ");
 		//write_text(temp_buffer);
 		//write_text("^");
-		strncpy(resolved_cstring->value, (const char *)s, i);
-		resolved_cstring->value[i] = 0;
+		Common::strcpy_s(resolved_cstring->value, (const char *)s);
 		//sprintf(temp_buffer, "Setting field %d to ~%s~^", field_no, (const char *) s);
 		//write_text(temp_buffer);
 		// INCREMENT THE FIELD NUMBER SO THE NEXT ONE GETS STORED IN THE RIGHT CONSTANT
@@ -379,7 +378,7 @@ int execute(const char *funcname) {
 #endif
 
 
-	strncpy(called_name, funcname, 1023);
+	Common::strlcpy(called_name, funcname, 1024);
 
 	/* GET THE FUNCTION OBJECT BY THE FUNCTION NAME */
 	resolved_function = function_resolve(called_name);
@@ -412,8 +411,8 @@ int execute(const char *funcname) {
 
 	// SET function_name TO THE CORE NAME STORED IN THE FUNCTION OBJECT
 	// LEAVING called_name TO CONTAIN THE FULL ARGUMENT LIST
-	strncpy(function_name, executing_function->name, 80);
-	strncpy(cstring_resolve("function_name")->value, executing_function->name, 80);
+	Common::strlcpy(function_name, executing_function->name, 81);
+	Common::strlcpy(cstring_resolve("function_name")->value, executing_function->name, sizeof(((string_type *)0)->value));
 
 	//sprintf(temp_buffer, "--- starting to execute %s^", function_name);
 	//write_text(temp_buffer);
@@ -886,7 +885,7 @@ int execute(const char *funcname) {
 				        || !strcmp(argument_buffer, "*anywhere")
 				        || !strcmp(argument_buffer, "*present")) {
 					criterion_type = CRI_SCOPE;
-					strncpy(scope_criterion, argument_buffer, 20);
+					Common::strlcpy(scope_criterion, argument_buffer, sizeof(scope_criterion));
 				} else if ((criterion_value = attribute_resolve(argument_buffer))) {
 					criterion_type = CRI_ATTRIBUTE;
 				} else if ((criterion_value = user_attribute_resolve(argument_buffer))) {
@@ -1396,9 +1395,9 @@ int execute(const char *funcname) {
 
 					// COPY THE VARIABLE OF THE CGI VARIABLE INTO THE SPECIFIED STRING VARIABLE
 					if (getenv(text_of_word(2)) != NULL) {
-						strncpy(resolved_setstring->value, getenv(text_of_word(2)), 255);
+						Common::strlcpy(resolved_setstring->value, getenv(text_of_word(2)), 256);
 					} else {
-						strncpy(resolved_setstring->value, "", 255);
+						resolved_setstring->value[0] = '\0';
 					}
 				}
 			} else if (!strcmp(word[0], "button")) {
@@ -1595,7 +1594,7 @@ int execute(const char *funcname) {
 
 				// TEXT BUFFER IS THE NORMAL ARRAY FOR HOLDING THE PLAYERS
 				// MOVE FOR PROCESSING
-				strncpy(text_buffer, proxy_buffer, 1024);
+				Common::strlcpy(text_buffer, proxy_buffer, 1024);
 
 				command_encapsulate();
 
@@ -1914,12 +1913,10 @@ int execute(const char *funcname) {
 					/* setstring_buffer IS NOW FILLED, COPY THE UP TO 256 BYTES OF
 					 * IT INTO THE STRING */
 					if (!strcmp(word[0], "setstring")) {
-						strncpy(resolved_setstring->value, setstring_buffer, 255);
+						Common::strlcpy(resolved_setstring->value, setstring_buffer, 256);
 					} else {
-						/* CALCULATE HOW MUCH SPACE IS LEFT IN THE STRING */
-						counter = 255 - strlen(resolved_setstring->value);
 						/* THIS IS A addstring COMMAND, SO USE STRNCAT INSTEAD */
-						strncat(resolved_setstring->value, setstring_buffer, counter);
+						Common::strlcat(resolved_setstring->value, setstring_buffer, 256);
 					}
 				}
 			} else if (!strcmp(word[0], "padstring")) {
@@ -1946,7 +1943,7 @@ int execute(const char *funcname) {
 
 					/* setstring_buffer IS NOW FILLED, COPY THE UP TO 256 BYTES OF
 					 * IT INTO THE STRING */
-					strncpy(resolved_setstring->value, setstring_buffer, 255);
+					Common::strlcpy(resolved_setstring->value, setstring_buffer, 256);
 				}
 			} else if (!strcmp(word[0], "return")) {
 				/* RETURN FROM THIS FUNCTION, POSSIBLY RETURNING AN INTEGER VALUE */
@@ -2659,17 +2656,17 @@ void pop_stack() {
 	/* RESTORE THE CONTENTS OF called_name */
 	//for (counter = 0; counter < 256; counter++)
 	//called_name[counter] = backup[stack].called_name[counter];
-	strncpy(called_name, backup[stack].called_name, 1023);
+	Common::strlcpy(called_name, backup[stack].called_name, 1024);
 
 	/* RESTORE THE CONTENTS OF scope_criterion */
 	//for (counter = 0; counter < 21; counter++)
 	//  scope_criterion[counter] = backup[stack].scope_criterion[counter];
-	strncpy(scope_criterion, backup[stack].scope_criterion, 20);
+	Common::strlcpy(scope_criterion, backup[stack].scope_criterion, sizeof(scope_criterion));
 
 	/* RESTORE THE STORED FUNCTION NAMES THAT ARE USED WHEN AN
 	 * 'override' COMMAND IS ENCOUNTERED IN THE CURRENT FUNCTION */
-	strncpy(override_, backup[stack]._override, 80);
-	strncpy(default_function, backup[stack].default_function, 80);
+	Common::strlcpy(override_, backup[stack]._override, 81);
+	Common::strlcpy(default_function, backup[stack].default_function, 84);
 
 	/* RESTORE ALL THE WORD POINTERS */
 	for (counter = 0; counter < MAX_WORDS; counter++) {
@@ -2680,8 +2677,8 @@ void pop_stack() {
 	executing_function = backup[stack].function;
 
 	if (executing_function != nullptr) {
-		strncpy(function_name, executing_function->name, 80);
-		strncpy(cstring_resolve("function_name")->value, executing_function->name, 80);
+		Common::strlcpy(function_name, executing_function->name, 81);
+		Common::strlcpy(cstring_resolve("function_name")->value, executing_function->name, 81);
 	}
 
 	wp = backup[stack].wp;
@@ -2745,15 +2742,15 @@ void push_stack(int32 file_pointer) {
 			backup[stack].text_buffer[counter] = text_buffer[counter];
 
 		/* MAKE A COPY OF THE CURRENT CONTENTS OF called_name */
-		strncpy(backup[stack].called_name, called_name, 1023);
+		Common::strlcpy(backup[stack].called_name, called_name, 1024);
 
 		// MAKE A COPY OF THE CURRENT CONTENTS OF scope_criterion
-		strncpy(backup[stack].scope_criterion, scope_criterion, 20);
+		Common::strlcpy(backup[stack].scope_criterion, scope_criterion, 21);
 
 		/* COPY THE STORED FUNCTION NAMES THAT ARE USED WHEN AN
 		 * 'override' COMMAND IS ENCOUNTERED IN THE CURRENT FUNCTION */
-		strncpy(backup[stack]._override, override_, 80);
-		strncpy(backup[stack].default_function, default_function, 80);
+		Common::strlcpy(backup[stack]._override, override_, 81);
+		Common::strlcpy(backup[stack].default_function, default_function, 81);
 
 		/* PUSH ALL THE WORD POINTERS ONTO THE STACK */
 		for (counter = 0; counter < MAX_WORDS; counter++) {
@@ -2785,7 +2782,7 @@ void push_stack(int32 file_pointer) {
 		if (current_cstring != nullptr) {
 			do {
 				if (!strcmp(current_cstring->name, "string_arg")) {
-					strncpy(backup[stack].str_arguments[index++], current_cstring->value, 255);
+					Common::strlcpy(backup[stack].str_arguments[index++], current_cstring->value, 256);
 				}
 
 				current_cstring = current_cstring->next_string;
@@ -2893,10 +2890,10 @@ void push_proxy() {
 		if (current_cstring != nullptr) {
 			do {
 				if (!strcmp(current_cstring->name, "$string")) {
-					strncpy(proxy_backup[proxy_stack].text[text++], current_cstring->value, 255);
-					proxy_backup[proxy_stack].text[counter++][255] = 0;
+					Common::strlcpy(proxy_backup[proxy_stack].text[text++], current_cstring->value, 256);
+					counter++;
 				} else if (!strcmp(current_cstring->name, "$word")) {
-					strncpy(proxy_backup[proxy_stack].command[command++], current_cstring->value, 255);
+					Common::strlcpy(proxy_backup[proxy_stack].command[command++], current_cstring->value, 256);
 				}
 
 				current_cstring = current_cstring->next_string;
@@ -3167,8 +3164,7 @@ void add_cinteger(const char *name, int value) {
 			}
 			current_cinteger->next_cinteger = new_cinteger;
 		}
-		strncpy(new_cinteger->name, name, 40);
-		new_cinteger->name[40] = 0;
+		Common::strlcpy(new_cinteger->name, name, 41);
 		new_cinteger->value = value;
 		new_cinteger->next_cinteger = nullptr;
 	}
@@ -3225,10 +3221,8 @@ void add_cstring(const char *name, const char *value) {
 			}
 			current_cstring->next_string = new_string;
 		}
-		strncpy(new_string->name, name, 40);
-		new_string->name[40] = 0;
-		strncpy(new_string->value, value, 255);
-		new_string->value[255] = 0;
+		Common::strlcpy(new_string->name, name, 41);
+		Common::strlcpy(new_string->value, value, 256);
 		new_string->next_string = nullptr;
 	}
 }
diff --git a/engines/glk/jacl/parser.cpp b/engines/glk/jacl/parser.cpp
index a89d30805c5..c79f355db7c 100644
--- a/engines/glk/jacl/parser.cpp
+++ b/engines/glk/jacl/parser.cpp
@@ -385,10 +385,10 @@ void call_functions(const char *base_name) {
 	 * PASS. IF THE COMMAND FAILS, 'TIME' WILL BE SET TO FALSE */
 	TIME->value = TRUE;
 
-	strncpy(base_function, base_name + 1, 80);
+	Common::strlcpy(base_function, base_name + 1, 81);
 	Common::strcat_s(base_function, "_");
 
-	strncpy(override_, base_function, 80);
+	Common::strlcpy(override_, base_function, 81);
 
 	Common::strcpy_s(before_function, "+before_");
 	Common::strcat_s(before_function, base_name + 1);
diff --git a/engines/glk/level9/os_glk.cpp b/engines/glk/level9/os_glk.cpp
index 0f65b2ba9fd..1c560e002f7 100644
--- a/engines/glk/level9/os_glk.cpp
+++ b/engines/glk/level9/os_glk.cpp
@@ -1289,8 +1289,8 @@ static void gln_graphics_locate_bitmaps(const char *gamefile) {
 	basename = gamefile;
 
 	/* Take a copy of the directory part of the filename. */
-	dirname = (char *)gln_malloc(basename - gamefile + 1);
-	strncpy(dirname, gamefile, basename - gamefile);
+	dirname = (char *)gln_malloc(/*basename - gamefile +*/ 1);
+	//strncpy(dirname, gamefile, basename - gamefile);
 	dirname[basename - gamefile] = '\0';
 
 	/*
diff --git a/engines/glk/tads/tads2/vocabulary_parser.cpp b/engines/glk/tads/tads2/vocabulary_parser.cpp
index 97e23fb100b..6d53a676a87 100644
--- a/engines/glk/tads/tads2/vocabulary_parser.cpp
+++ b/engines/glk/tads/tads2/vocabulary_parser.cpp
@@ -4753,8 +4753,7 @@ static void voc_get_spec_str(voccxdef *ctx, char vocw_id,
 	/* if we didn't find it, use the default */
 	if (!found)
 	{
-		strncpy(buf, default_name, (size_t)buflen);
-		buf[buflen - 1] = '\0';
+		Common::strlcpy(buf, default_name, (size_t)buflen);
 	}
 }
 


Commit: f816efdbb0854edea23977f2eeac6b0c93d503cb
    https://github.com/scummvm/scummvm/commit/f816efdbb0854edea23977f2eeac6b0c93d503cb
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-06T17:27:21+01:00

Commit Message:
MUTATIONOFJB: Fix strncpy usage

Changed paths:
    engines/mutationofjb/commands/changecommand.cpp


diff --git a/engines/mutationofjb/commands/changecommand.cpp b/engines/mutationofjb/commands/changecommand.cpp
index beb0fac140d..69d5f763511 100644
--- a/engines/mutationofjb/commands/changecommand.cpp
+++ b/engines/mutationofjb/commands/changecommand.cpp
@@ -70,7 +70,7 @@ bool ChangeCommandParser::parseValueString(const Common::String &valueString, bo
 	if (valueString.hasPrefix("NM")) {
 		reg = ChangeCommand::NM;
 		op = ChangeCommand::SetValue;
-		strncpy(ccv._strVal, val, MAX_ENTITY_NAME_LENGTH);
+		Common::strlcpy(ccv._strVal, val, MAX_ENTITY_NAME_LENGTH + 1);
 	} else if (valueString.hasPrefix("LT")) {
 		reg = ChangeCommand::LT;
 		ccv._byteVal = parseInteger(val, op);
@@ -354,7 +354,7 @@ Command::ExecuteResult ChangeDoorCommand::execute(ScriptExecutionContext &script
 
 	switch (_register) {
 	case NM:
-		strncpy(door->_name, _value._strVal, MAX_ENTITY_NAME_LENGTH);
+		Common::strlcpy(door->_name, _value._strVal, MAX_ENTITY_NAME_LENGTH + 1);
 		break;
 	case LT:
 		door->_destSceneId = _value._byteVal;
@@ -477,7 +477,7 @@ Command::ExecuteResult ChangeStaticCommand::execute(ScriptExecutionContext &scri
 		stat->_active = _value._byteVal;
 		break;
 	case NM:
-		strncpy(stat->_name, _value._strVal, MAX_ENTITY_NAME_LENGTH);
+		Common::strlcpy(stat->_name, _value._strVal, MAX_ENTITY_NAME_LENGTH + 1);
 		break;
 	case XX:
 		stat->_x = _value._wordVal;


Commit: c236ce82e60606af1d7040ba59ac2ed06ef7d3c6
    https://github.com/scummvm/scummvm/commit/c236ce82e60606af1d7040ba59ac2ed06ef7d3c6
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-06T17:27:21+01:00

Commit Message:
SAGA: Fix strncpy usage

Changed paths:
    engines/saga/actor.cpp
    engines/saga/interface.cpp


diff --git a/engines/saga/actor.cpp b/engines/saga/actor.cpp
index 1568b1a3f3f..95c3df8cc06 100644
--- a/engines/saga/actor.cpp
+++ b/engines/saga/actor.cpp
@@ -1107,9 +1107,9 @@ void Actor::drawSpeech() {
 	outputString.resize(stringLength + 1);
 
 	if (_activeSpeech.speechFlags & kSpeakSlow)
-		strncpy(&outputString.front(), _activeSpeech.strings[0], _activeSpeech.slowModeCharIndex + 1);
+		Common::strlcpy(&outputString.front(), _activeSpeech.strings[0], _activeSpeech.slowModeCharIndex + 2);
 	else
-		strncpy(&outputString.front(), _activeSpeech.strings[0], stringLength);
+		Common::strlcpy(&outputString.front(), _activeSpeech.strings[0], stringLength + 1);
 
 	if (_activeSpeech.actorsCount > 1) {
 		height = _vm->_font->getHeight(kKnownFontScript);
diff --git a/engines/saga/interface.cpp b/engines/saga/interface.cpp
index 76d82415333..ec914ad7017 100644
--- a/engines/saga/interface.cpp
+++ b/engines/saga/interface.cpp
@@ -1203,10 +1203,10 @@ bool Interface::processTextInput(Common::KeyState keystate) {
 	case Common::KEYCODE_DELETE:
 		if (_textInputPos <= _textInputStringLength) {
 			if (_textInputPos != 1) {
-				strncpy(tempString, _textInputString, _textInputPos - 1);
+				Common::strlcpy(tempString, _textInputString, _textInputPos);
 			}
 			if (_textInputPos != _textInputStringLength) {
-				strncat(tempString, &_textInputString[_textInputPos], _textInputStringLength - _textInputPos);
+				Common::strlcat(tempString, &_textInputString[_textInputPos], _textInputStringLength + 1);
 			}
 			Common::strcpy_s(_textInputString, tempString);
 			_textInputStringLength = strlen(_textInputString);
@@ -1243,14 +1243,14 @@ bool Interface::processTextInput(Common::KeyState keystate) {
 					break;
 				}
 				if (_textInputPos != 1) {
-					strncpy(tempString, _textInputString, _textInputPos - 1);
+					Common::strlcpy(tempString, _textInputString, _textInputPos);
 					Common::strcat_s(tempString, ch);
 				}
 				if ((_textInputStringLength == 0) || (_textInputPos == 1)) {
 					Common::strcpy_s(tempString, ch);
 				}
 				if ((_textInputStringLength != 0) && (_textInputPos != _textInputStringLength)) {
-					strncat(tempString, &_textInputString[_textInputPos - 1], _textInputStringLength - _textInputPos + 1);
+					Common::strlcat(tempString, &_textInputString[_textInputPos - 1], _textInputStringLength + 1);
 				}
 
 				Common::strcpy_s(_textInputString, tempString);
@@ -2496,7 +2496,7 @@ bool Interface::converseAddText(const char *text, int strId, int replyId, byte r
 		}
 
 		_converseText[_converseTextCount].text.resize(i + 1);
-		strncpy(&_converseText[_converseTextCount].text.front(), _converseWorkString, i);
+		Common::strlcpy(&_converseText[_converseTextCount].text.front(), _converseWorkString, i + 1);
 
 		_converseText[_converseTextCount].strId = strId;
 		_converseText[_converseTextCount].text[i] = 0;
@@ -2512,7 +2512,7 @@ bool Interface::converseAddText(const char *text, int strId, int replyId, byte r
 		if (len == i)
 			break;
 
-		strncpy(_converseWorkString, &_converseWorkString[i + 1], len - i);
+		Common::strlcpy(_converseWorkString, &_converseWorkString[i + 1], CONVERSE_MAX_WORK_STRING);
 	}
 
 	_converseStrCount++;


Commit: c73fac1cda2f9f8752e8607c09a679f0fbd13c02
    https://github.com/scummvm/scummvm/commit/c73fac1cda2f9f8752e8607c09a679f0fbd13c02
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2022-11-06T17:27:21+01:00

Commit Message:
GUI: Fix strncpy usage

Changed paths:
    gui/predictivedialog.cpp


diff --git a/gui/predictivedialog.cpp b/gui/predictivedialog.cpp
index 74ae709a86a..1a0903eaba2 100644
--- a/gui/predictivedialog.cpp
+++ b/gui/predictivedialog.cpp
@@ -509,8 +509,7 @@ void PredictiveDialog::processButton(ButtonId button) {
 			if (_mode == kModePre && _unitedDict.dictActLine && _numMatchingWords > 1 && _wordNumber != 0)
 				bringWordtoTop(_unitedDict.dictActLine, _wordNumber);
 
-			strncpy(_temp, _currentWord.c_str(), _currentCode.size());
-			_temp[_currentCode.size()] = 0;
+			Common::strcpy_s(_temp, _currentWord.c_str());
 			_prefix += _temp;
 			_prefix += " ";
 			_currentCode.clear();
@@ -564,8 +563,7 @@ void PredictiveDialog::processButton(ButtonId button) {
 				if (_unitedDict.dictActLine && _numMatchingWords > 1) {
 					_wordNumber = (_wordNumber + 1) % _numMatchingWords;
 					char tmp[kMaxLineLen];
-					strncpy(tmp, _unitedDict.dictActLine, kMaxLineLen);
-					tmp[kMaxLineLen - 1] = 0;
+					Common::strlcpy(tmp, _unitedDict.dictActLine, kMaxLineLen);
 					char *tok = strtok(tmp, " ");
 					for (uint8 i = 0; i <= _wordNumber; i++)
 						tok = strtok(nullptr, " ");
@@ -697,8 +695,7 @@ void PredictiveDialog::bringWordtoTop(char *str, int wordnum) {
 
 	if (!str)
 		return;
-	strncpy(buf, str, kMaxLineLen);
-	buf[kMaxLineLen - 1] = 0;
+	Common::strlcpy(buf, str, kMaxLineLen);
 	char *word = strtok(buf, " ");
 	if (!word) {
 		debug(5, "Predictive Dialog: Invalid dictionary line");
@@ -771,8 +768,7 @@ bool PredictiveDialog::matchWord() {
 	_wordNumber = 0;
 	if (0 == strncmp(_unitedDict.dictLine[line], _currentCode.c_str(), _currentCode.size())) {
 		char tmp[kMaxLineLen];
-		strncpy(tmp, _unitedDict.dictLine[line], kMaxLineLen);
-		tmp[kMaxLineLen - 1] = 0;
+		Common::strlcpy(tmp, _unitedDict.dictLine[line], kMaxLineLen);
 		char *tok;
 		strtok(tmp, " ");
 		tok = strtok(nullptr, " ");
@@ -821,10 +817,10 @@ void PredictiveDialog::addWord(Dict &dict, const Common::String &word, const Com
 			newLine = (char *)malloc(newLineSize + 1);
 
 			char *ptr = newLine;
-			strncpy(ptr, dict.dictLine[line], oldLineSize);
+			Common::strcpy_s(ptr, newLineSize + 1, dict.dictLine[line]);
 			ptr += oldLineSize;
-			Common::String tmp = ' ' + word + '\0';
-			strncpy(ptr, tmp.c_str(), tmp.size());
+			Common::String tmp = ' ' + word;
+			Common::strcpy_s(ptr, newLineSize + 1 - oldLineSize, tmp.c_str());
 
 			dict.dictLine[line] = newLine;
 			_memoryList[_numMemory++] = newLine;
@@ -846,7 +842,7 @@ void PredictiveDialog::addWord(Dict &dict, const Common::String &word, const Com
 					int len = (predictLine == _predictiveDict.dictLineCount - 1) ? &_predictiveDict.dictText[_predictiveDict.dictTextSize] - _predictiveDict.dictLine[predictLine] :
 					          _predictiveDict.dictLine[predictLine + 1] - _predictiveDict.dictLine[predictLine];
 					newLine = (char *)malloc(len);
-					strncpy(newLine, _predictiveDict.dictLine[predictLine], len);
+					Common::strlcpy(newLine, _predictiveDict.dictLine[predictLine], len);
 				} else {
 					// if there is no word in predictive dictionary, we need to copy to
 					// user dictionary mathed line + new word.
@@ -854,27 +850,26 @@ void PredictiveDialog::addWord(Dict &dict, const Common::String &word, const Com
 					          _predictiveDict.dictLine[predictLine + 1] - _predictiveDict.dictLine[predictLine];
 					newLine = (char *)malloc(len + word.size() + 1);
 					char *ptr = newLine;
-					strncpy(ptr, _predictiveDict.dictLine[predictLine], len);
+					Common::strlcpy(ptr, _predictiveDict.dictLine[predictLine], len);
 					ptr[len - 1] = ' ';
 					ptr += len;
-					strncpy(ptr, word.c_str(), word.size());
-					ptr[len + word.size()] = '\0';
+					Common::strlcpy(ptr, word.c_str(), word.size() + 1);
 				}
 			} else {
 				// if we didnt find line in predictive dialog, we should copy to user dictionary
 				// code + word
 				Common::String tmp;
-				tmp = tmpCode + word + '\0';
-				newLine = (char *)malloc(tmp.size());
-				strncpy(newLine, tmp.c_str(), tmp.size());
+				tmp = tmpCode + word;
+				newLine = (char *)malloc(tmp.size() + 1);
+				Common::strcpy_s(newLine, tmp.size() + 1, tmp.c_str());
 			}
 		} else {
 			// if want to insert line to different from user dictionary, we should copy to this
 			// dictionary code + word
 			Common::String tmp;
-			tmp = tmpCode + word + '\0';
-			newLine = (char *)malloc(tmp.size());
-			strncpy(newLine, tmp.c_str(), tmp.size());
+			tmp = tmpCode + word;
+			newLine = (char *)malloc(tmp.size() + 1);
+			Common::strcpy_s(newLine, tmp.size() + 1, tmp.c_str());
 		}
 	}
 




More information about the Scummvm-git-logs mailing list