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

digitall noreply at scummvm.org
Tue Feb 14 21:43:21 UTC 2023


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

Summary:
d65758cfea ULTIMA: NUVIE: Fix Format Truncation GCC Compiler Warnings


Commit: d65758cfea08a01b0be542733f4803a81696c943
    https://github.com/scummvm/scummvm/commit/d65758cfea08a01b0be542733f4803a81696c943
Author: D G Turner (digitall at scummvm.org)
Date: 2023-02-14T21:42:42Z

Commit Message:
ULTIMA: NUVIE: Fix Format Truncation GCC Compiler Warnings

Changed paths:
    engines/ultima/nuvie/files/tmx_map.cpp
    engines/ultima/nuvie/views/portrait_view_gump.cpp
    engines/ultima/nuvie/views/spell_view.cpp
    engines/ultima/nuvie/views/spell_view_gump.cpp


diff --git a/engines/ultima/nuvie/files/tmx_map.cpp b/engines/ultima/nuvie/files/tmx_map.cpp
index 655b9884e1c..c9fa7261d0e 100644
--- a/engines/ultima/nuvie/files/tmx_map.cpp
+++ b/engines/ultima/nuvie/files/tmx_map.cpp
@@ -86,8 +86,6 @@ void TMXMap::writeLayer(NuvieIOFileWrite *tmx, uint16 sideLength, Std::string la
 
 	tmx->writeBuf((const unsigned char *)header.c_str(), header.length());
 
-	char buf[5]; // 'nnnn\0'
-
 	uint16 mx, my;
 	for (my = 0; my < sideLength; my++) {
 		for (mx = 0; mx < sideLength; mx++) {
@@ -97,8 +95,9 @@ void TMXMap::writeLayer(NuvieIOFileWrite *tmx, uint16 sideLength, Std::string la
 			} else { //everything else is uint16
 				gid = ((const uint16 *)data)[my * sideLength + mx] + 1 + gidOffset;
 			}
-			snprintf(buf, sizeof(buf), "%d", gid);
-			tmx->writeBuf((const unsigned char *)buf, strlen(buf));
+			// 'nnnn\0'
+			Common::String temp = Common::String::format("%d", gid);
+			tmx->writeBuf((const unsigned char *)temp.c_str(), temp.size());
 			if (mx < sideLength - 1 || my < sideLength - 1) { //don't write comma after last element in the array.
 				tmx->write1(',');
 			}
@@ -194,10 +193,9 @@ bool TMXMap::exportMapLevel(uint8 level) {
 	NuvieIOFileWrite tmx;
 	uint16 width = map->get_width(level);
 	mapdata = map->get_map_data(level);
-	char level_string[3]; // 'nn\0'
+	Common::String level_string = Common::String::format("%d", level); // 'nn\0'
 	Std::string filename;
-	snprintf(level_string, sizeof(level_string), "%d", level);
-	build_path(savedir, savename + "_" + Std::string(level_string) + ".tmx", filename);
+	build_path(savedir, savename + "_" + Std::string(level_string.c_str()) + ".tmx", filename);
 
 	tmx.open(filename);
 	Std::string swidth = sint32ToString((sint32)width);
diff --git a/engines/ultima/nuvie/views/portrait_view_gump.cpp b/engines/ultima/nuvie/views/portrait_view_gump.cpp
index c7f59a58bc7..77c4944cc83 100644
--- a/engines/ultima/nuvie/views/portrait_view_gump.cpp
+++ b/engines/ultima/nuvie/views/portrait_view_gump.cpp
@@ -133,7 +133,7 @@ void PortraitViewGump::right_arrow() {
 }
 
 void PortraitViewGump::Display(bool full_redraw) {
-	char buf[6]; //xxxxx\n
+	Common::String buf; //xxxxx\n
 //display_level_text();
 //display_spell_list_text();
 	Common::Rect dst;
@@ -150,55 +150,54 @@ void PortraitViewGump::Display(bool full_redraw) {
 
 	font->textOut(screen->get_sdl_surface(), area.left + 29 + w, area.top + 6, actor->get_name());
 
-	snprintf(buf, 5, "%d", actor->get_strength());
-	font->textExtent(buf, &w, &h);
-	font->textOut(screen->get_sdl_surface(), area.left + 170 - w, area.top + 18, buf);
+	buf = Common::String::format("%d", actor->get_strength());
+	font->textExtent(buf.c_str(), &w, &h);
+	font->textOut(screen->get_sdl_surface(), area.left + 170 - w, area.top + 18, buf.c_str());
 
-	snprintf(buf, 5, "%d", actor->get_dexterity());
-	font->textExtent(buf, &w, &h);
-	font->textOut(screen->get_sdl_surface(), area.left + 170 - w, area.top + 27, buf);
+	buf = Common::String::format("%d", actor->get_dexterity());
+	font->textExtent(buf.c_str(), &w, &h);
+	font->textOut(screen->get_sdl_surface(), area.left + 170 - w, area.top + 27, buf.c_str());
 
-	snprintf(buf, 5, "%d", actor->get_intelligence());
-	font->textExtent(buf, &w, &h);
-	font->textOut(screen->get_sdl_surface(), area.left + 170 - w, area.top + 36, buf);
+	buf = Common::String::format("%d", actor->get_intelligence());
+	font->textExtent(buf.c_str(), &w, &h);
+	font->textOut(screen->get_sdl_surface(), area.left + 170 - w, area.top + 36, buf.c_str());
 
 	font->setColoring(0x6c, 0x00, 0x00, 0xbc, 0x34, 0x00, 0x00, 0x00, 0x00);
 
-	snprintf(buf, 5, "%d", actor->get_magic());
-	font->textExtent(buf, &w, &h);
-	font->textOut(screen->get_sdl_surface(), area.left + 142 - w, area.top + 55, buf);
+	buf = Common::String::format("%d", actor->get_magic());
+	font->textExtent(buf.c_str(), &w, &h);
+	font->textOut(screen->get_sdl_surface(), area.left + 142 - w, area.top + 55, buf.c_str());
 
-	snprintf(buf, 5, "%d", actor->get_maxmagic());
-	font->textExtent(buf, &w, &h);
-	font->textOut(screen->get_sdl_surface(), area.left + 170 - w, area.top + 55, buf);
+	buf = Common::String::format("%d", actor->get_maxmagic());
+	font->textExtent(buf.c_str(), &w, &h);
+	font->textOut(screen->get_sdl_surface(), area.left + 170 - w, area.top + 55, buf.c_str());
 
 	font->setColoring(0x00, 0x3c, 0x70, 0x74, 0x74, 0x74, 0x00, 0x00, 0x00);
 
-	snprintf(buf, 5, "%d", actor->get_hp());
-	font->textExtent(buf, &w, &h);
-	font->textOut(screen->get_sdl_surface(), area.left + 142 - w, area.top + 64, buf);
+	buf = Common::String::format("%d", actor->get_hp());
+	font->textExtent(buf.c_str(), &w, &h);
+	font->textOut(screen->get_sdl_surface(), area.left + 142 - w, area.top + 64, buf.c_str());
 
-	snprintf(buf, 5, "%d", actor->get_maxhp());
-	font->textExtent(buf, &w, &h);
-	font->textOut(screen->get_sdl_surface(), area.left + 170 - w, area.top + 64, buf);
+	buf = Common::String::format("%d", actor->get_maxhp());
+	font->textExtent(buf.c_str(), &w, &h);
+	font->textOut(screen->get_sdl_surface(), area.left + 170 - w, area.top + 64, buf.c_str());
 
 	font->setColoring(0xa8, 0x28, 0x00, 0xa8, 0x54, 0x00, 0x00, 0x00, 0x00);
 
-	snprintf(buf, 5, "%d", actor->get_level());
-	font->textExtent(buf, &w, &h);
-	font->textOut(screen->get_sdl_surface(), area.left + 142 - w, area.top + 73, buf);
+	buf = Common::String::format("%d", actor->get_level());
+	font->textExtent(buf.c_str(), &w, &h);
+	font->textOut(screen->get_sdl_surface(), area.left + 142 - w, area.top + 73, buf.c_str());
 
-	snprintf(buf, 5, "%d", actor->get_exp());
-	font->textExtent(buf, &w, &h);
-	font->textOut(screen->get_sdl_surface(), area.left + 170 - w, area.top + 73, buf);
+	buf = Common::String::format("%d", actor->get_exp());
+	font->textExtent(buf.c_str(), &w, &h);
+	font->textOut(screen->get_sdl_surface(), area.left + 170 - w, area.top + 73, buf.c_str());
 
-	if (show_cursor)
+	if (show_cursor) {
 		screen->blit(area.left + cursor_xoff, area.top + cursor_yoff, (const unsigned char *)cursor_tile->data, 8, 16, 16, 16, true);
+	}
+
 	update_display = false;
 	screen->update(area.left, area.top, area.width(), area.height());
-
-
-	return;
 }
 
 GUI_status PortraitViewGump::set_cursor_pos(gumpCursorPos pos) {
diff --git a/engines/ultima/nuvie/views/spell_view.cpp b/engines/ultima/nuvie/views/spell_view.cpp
index 686d0dbedec..3b0976cefe6 100644
--- a/engines/ultima/nuvie/views/spell_view.cpp
+++ b/engines/ultima/nuvie/views/spell_view.cpp
@@ -132,7 +132,6 @@ void SpellView::Display(bool full_redraw) {
 		screen->update(area.left, area.top, area.width(), area.height());
 	}
 #endif
-	return;
 }
 
 uint8 SpellView::fill_cur_spell_list() {
@@ -293,17 +292,13 @@ void SpellView::display_spell_list_text() {
 }
 
 void SpellView::display_spell_text(Spell *spell, uint16 line_num, uint8 selected_spell) {
-	char num_str[4];
 	line_num++;
 
 	font->drawString(screen, spell->name, area.left + 16, area.top + (line_num * 8));
-	snprintf(num_str, 3, "%d", get_available_spell_count(spell));
-	font->drawString(screen, num_str, area.left + NEWMAGIC_BMP_W - 24, area.top + (line_num * 8));
+	font->drawString(screen, Common::String::format("%d", get_available_spell_count(spell)).c_str(), area.left + NEWMAGIC_BMP_W - 24, area.top + (line_num * 8));
 
 	if (spell->num == selected_spell)
 		font->drawChar(screen, 26, area.left + 8, area.top + (line_num * 8));
-
-	return;
 }
 
 uint16 SpellView::get_available_spell_count(Spell *s) {
@@ -341,7 +336,6 @@ void SpellView::add_command_icons(Screen *tmp_screen, void *view_manager) {
 	button_image2 = tmp_screen->create_sdl_surface_from(tile->data, 8, 16, 16, 16);
 	right_button = new GUI_Button(this, 3 * 16, NEWMAGIC_BMP_H, button_image, button_image2, this);
 	this->AddWidget(right_button);
-
 }
 
 void SpellView::event_mode_select_spell() {
diff --git a/engines/ultima/nuvie/views/spell_view_gump.cpp b/engines/ultima/nuvie/views/spell_view_gump.cpp
index 2978034aeec..d7fc17ef36c 100644
--- a/engines/ultima/nuvie/views/spell_view_gump.cpp
+++ b/engines/ultima/nuvie/views/spell_view_gump.cpp
@@ -198,17 +198,15 @@ void SpellViewGump::loadCircleSuffix(Std::string datadir, Std::string image) {
 
 void SpellViewGump::printSpellQty(uint8 spellNum, uint16 x, uint16 y) {
 	Magic *m = Game::get_game()->get_magic();
-	char num_str[4];
 
 	Spell *spell = m->get_spell((uint8)spellNum);
 
 	uint16 qty = get_available_spell_count(spell);
-	snprintf(num_str, 3, "%d", qty);
 
 	if (qty < 10)
 		x += 5;
 
-	font->textOut(bg_image, x, y, num_str);
+	font->textOut(bg_image, x, y, Common::String::format("%d", qty).c_str());
 }
 
 void SpellViewGump::Display(bool full_redraw) {




More information about the Scummvm-git-logs mailing list