AGS: Replaced strcpy with snprintf in old string API impls

From upstream 44d99badb2708fb99b1f7b9bc024082d570706c7
This commit is contained in:
Thierry Crozat 2022-06-19 16:18:17 +01:00
parent 2c7d51ce16
commit 8d36266724
10 changed files with 14 additions and 13 deletions

View File

@ -127,7 +127,7 @@ const char *Button_GetText_New(GUIButton *butt) {
}
void Button_GetText(GUIButton *butt, char *buffer) {
strcpy(buffer, butt->GetText().GetCStr());
snprintf(buffer, MAX_MAXSTRLEN, "%s", butt->GetText().GetCStr());
}
void Button_SetText(GUIButton *butt, const char *newtx) {

View File

@ -548,7 +548,7 @@ void GetLocationName(int xxx, int yyy, char *tempo) {
if (_GP(play).get_loc_name_last_time != 1000 + mover)
GUI::MarkSpecialLabelsForUpdate(kLabelMacro_Overhotspot);
_GP(play).get_loc_name_last_time = 1000 + mover;
strcpy(tempo, get_translation(_GP(game).invinfo[mover].name));
snprintf(tempo, MAX_MAXSTRLEN, "%s", get_translation(_GP(game).invinfo[mover].name));
} else if ((_GP(play).get_loc_name_last_time > 1000) && (_GP(play).get_loc_name_last_time < 1000 + MAX_INV)) {
// no longer selecting an item
GUI::MarkSpecialLabelsForUpdate(kLabelMacro_Overhotspot);
@ -578,7 +578,7 @@ void GetLocationName(int xxx, int yyy, char *tempo) {
// on character
if (loctype == LOCTYPE_CHAR) {
onhs = _G(getloctype_index);
strcpy(tempo, get_translation(_GP(game).chars[onhs].name));
snprintf(tempo, MAX_MAXSTRLEN, "%s", get_translation(_GP(game).chars[onhs].name));
if (_GP(play).get_loc_name_last_time != 2000 + onhs)
GUI::MarkSpecialLabelsForUpdate(kLabelMacro_Overhotspot);
_GP(play).get_loc_name_last_time = 2000 + onhs;
@ -587,7 +587,7 @@ void GetLocationName(int xxx, int yyy, char *tempo) {
// on object
if (loctype == LOCTYPE_OBJ) {
aa = _G(getloctype_index);
strcpy(tempo, get_translation(_G(croom)->obj[aa].name.GetCStr()));
snprintf(tempo, MAX_MAXSTRLEN, "%s", get_translation(_G(croom)->obj[aa].name.GetCStr()));
// Compatibility: < 3.1.1 games returned space for nameless object
// (presumably was a bug, but fixing it affected certain games behavior)
if (_G(loaded_game_file_version) < kGameVersion_311 && tempo[0] == 0) {
@ -600,7 +600,8 @@ void GetLocationName(int xxx, int yyy, char *tempo) {
return;
}
onhs = _G(getloctype_index);
if (onhs > 0) strcpy(tempo, get_translation(_G(croom)->hotspot[onhs].Name.GetCStr()));
if (onhs > 0)
snprintf(tempo, MAX_MAXSTRLEN, "%s", get_translation(_G(croom)->hotspot[onhs].Name.GetCStr()));
if (_GP(play).get_loc_name_last_time != onhs)
GUI::MarkSpecialLabelsForUpdate(kLabelMacro_Overhotspot);
_GP(play).get_loc_name_last_time = onhs;

View File

@ -86,7 +86,7 @@ void GetHotspotName(int hotspot, char *buffer) {
if ((hotspot < 0) || (hotspot >= MAX_ROOM_HOTSPOTS))
quit("!GetHotspotName: invalid hotspot number");
strcpy(buffer, get_translation(_G(croom)->hotspot[hotspot].Name.GetCStr()));
snprintf(buffer, MAX_MAXSTRLEN, "%s", get_translation(_G(croom)->hotspot[hotspot].Name.GetCStr()));
}
void RunHotspotInteraction(int hotspothere, int mood) {

View File

@ -85,7 +85,7 @@ int GetInvAt(int atx, int aty) {
void GetInvName(int indx, char *buff) {
VALIDATE_STRING(buff);
if ((indx < 0) | (indx >= _GP(game).numinvitems)) quit("!GetInvName: invalid inventory item specified");
strcpy(buff, get_translation(_GP(game).invinfo[indx].name));
snprintf(buff, MAX_MAXSTRLEN, "%s", get_translation(_GP(game).invinfo[indx].name));
}
int GetInvGraphic(int indx) {

View File

@ -386,7 +386,7 @@ void GetObjectName(int obj, char *buffer) {
if (!is_valid_object(obj))
quit("!GetObjectName: invalid object number");
strcpy(buffer, get_translation(_G(croom)->obj[obj].name.GetCStr()));
snprintf(buffer, MAX_MAXSTRLEN, "%s", get_translation(_G(croom)->obj[obj].name.GetCStr()));
}
void MoveObject(int objj, int xx, int yy, int spp) {

View File

@ -29,7 +29,7 @@ namespace AGS3 {
int SaidUnknownWord(char *buffer) {
VALIDATE_STRING(buffer);
strcpy(buffer, _GP(play).bad_parsed_word);
snprintf(buffer, MAX_MAXSTRLEN, "%s", _GP(play).bad_parsed_word);
if (_GP(play).bad_parsed_word[0] == 0)
return 0;
return 1;

View File

@ -68,7 +68,7 @@ int IsTranslationAvailable() {
int GetTranslationName(char *buffer) {
VALIDATE_STRING(buffer);
strcpy(buffer, get_translation_name().GetCStr());
snprintf(buffer, MAX_MAXSTRLEN, "%s", get_translation_name().GetCStr());
return IsTranslationAvailable();
}

View File

@ -39,7 +39,7 @@ const char *Label_GetText_New(GUILabel *labl) {
}
void Label_GetText(GUILabel *labl, char *buffer) {
strcpy(buffer, labl->GetText().GetCStr());
snprintf(buffer, MAX_MAXSTRLEN, "%s", labl->GetText().GetCStr());
}
void Label_SetText(GUILabel *labl, const char *newtx) {

View File

@ -76,7 +76,7 @@ void get_text_property(const StringIMap &st_prop, const StringIMap &rt_prop, con
return;
String val = get_property_value(st_prop, rt_prop, property, desc.DefaultValue);
strcpy(bufer, val.GetCStr());
snprintf(bufer, MAX_MAXSTRLEN, "%s", val.GetCStr());
}
const char *get_text_property_dynamic_string(const StringIMap &st_prop, const StringIMap &rt_prop, const char *property) {

View File

@ -38,7 +38,7 @@ const char *TextBox_GetText_New(GUITextBox *texbox) {
}
void TextBox_GetText(GUITextBox *texbox, char *buffer) {
strcpy(buffer, texbox->Text.GetCStr());
snprintf(buffer, MAX_MAXSTRLEN, "%s", texbox->Text.GetCStr());
}
void TextBox_SetText(GUITextBox *texbox, const char *newtex) {