diff --git a/src/app/commands/cmd_new_sprite_from_selection.cpp b/src/app/commands/cmd_new_sprite_from_selection.cpp index e14dd87fe..65e654277 100644 --- a/src/app/commands/cmd_new_sprite_from_selection.cpp +++ b/src/app/commands/cmd_new_sprite_from_selection.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2023 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -21,6 +21,7 @@ #include "doc/mask.h" #include "doc/palette.h" #include "doc/sprite.h" +#include "fmt/format.h" #include @@ -80,11 +81,13 @@ void NewSpriteFromSelectionCommand::onExecute(Context* context) std::unique_ptr dstDoc(new Doc(dstSprite.get())); dstSprite.release(); - char buf[1024]; - std::sprintf(buf, "%s-%dx%d-%dx%d", - base::get_file_title(doc->filename()).c_str(), - mask->bounds().x, mask->bounds().y, - mask->bounds().w, mask->bounds().h); + + const std::string buf = + fmt::format("{}-{}x{}-{}x{}", + base::get_file_title(doc->filename()), + mask->bounds().x, mask->bounds().y, + mask->bounds().w, mask->bounds().h); + dstDoc->setFilename(buf); dstDoc->setContext(context); dstDoc.release(); diff --git a/src/app/commands/filters/filter_target_buttons.cpp b/src/app/commands/filters/filter_target_buttons.cpp index 1082c3004..82a3a8089 100644 --- a/src/app/commands/filters/filter_target_buttons.cpp +++ b/src/app/commands/filters/filter_target_buttons.cpp @@ -16,6 +16,7 @@ #include "app/modules/gui.h" #include "app/ui/skin/skin_theme.h" #include "doc/image.h" +#include "fmt/format.h" #include "ui/box.h" #include "ui/button.h" #include "ui/theme.h" @@ -115,10 +116,10 @@ void FilterTargetButtons::updateFromCelsTarget() void FilterTargetButtons::updateComponentTooltip(Item* item, const char* channelName, int align) { if (item) { - char buf[256]; - std::sprintf(buf, "%s %s Component", - (item->isSelected() ? "Modify": "Ignore"), - channelName); + std::string buf = + fmt::format("{} {} Component", + (item->isSelected() ? "Modify": "Ignore"), + channelName); m_tooltips.addTooltipFor(item, buf, align); } } diff --git a/src/app/crash/data_recovery.cpp b/src/app/crash/data_recovery.cpp index 9ac528975..b9348930c 100644 --- a/src/app/crash/data_recovery.cpp +++ b/src/app/crash/data_recovery.cpp @@ -19,6 +19,7 @@ #include "base/fs.h" #include "base/thread.h" #include "base/time.h" +#include "fmt/format.h" #include "ui/system.h" #include @@ -55,10 +56,10 @@ DataRecovery::DataRecovery(Context* ctx) do { base::Time time = base::current_time(); - char buf[1024]; - sprintf(buf, "%04d%02d%02d-%02d%02d%02d-%d", - time.year, time.month, time.day, - time.hour, time.minute, time.second, pid); + std::string buf = + fmt::format("{:04}{:02}{:02}-{:02}{:02}{:02}-{}", + time.year, time.month, time.day, + time.hour, time.minute, time.second, pid); newSessionDir = base::join_path(m_sessionsDir, buf); diff --git a/src/app/file/file.cpp b/src/app/file/file.cpp index 95f592788..830beb2c6 100644 --- a/src/app/file/file.cpp +++ b/src/app/file/file.cpp @@ -401,7 +401,7 @@ FileOp* FileOp::createLoadDocumentOperation(Context* context, if (!(flags & FILE_LOAD_SEQUENCE_NONE)) { std::string left, right; int c, width, start_from; - char buf[512]; + std::string buf; // First of all, we must generate the list of files to load in the // sequence... @@ -412,7 +412,7 @@ FileOp* FileOp::createLoadDocumentOperation(Context* context, // Try to get more file names for (c=start_from+1; ; c++) { // Get the next file name - sprintf(buf, "%s%0*d%s", left.c_str(), width, c, right.c_str()); + buf = fmt::format("{0}{1:0{2}d}{3}", left, c, width, right); // If the file doesn't exist, we doesn't need more files to load if (!base::is_file(buf)) diff --git a/src/app/file/file_data.cpp b/src/app/file/file_data.cpp index 9645b9d87..6d3acc7a4 100644 --- a/src/app/file/file_data.cpp +++ b/src/app/file/file_data.cpp @@ -18,6 +18,7 @@ #include "doc/color.h" #include "doc/document.h" #include "doc/slice.h" +#include "fmt/format.h" #include "gfx/color.h" #include @@ -33,19 +34,19 @@ namespace { std::string color_to_hex(doc::color_t color) { - char buf[256]; + std::string buf; if (doc::rgba_geta(color) == 255) { - std::sprintf(buf, "#%02x%02x%02x", - doc::rgba_getr(color), - doc::rgba_getg(color), - doc::rgba_getb(color)); + buf = fmt::format("#{:02x}{:02x}{:02x}", + doc::rgba_getr(color), + doc::rgba_getg(color), + doc::rgba_getb(color)); } else { - std::sprintf(buf, "#%02x%02x%02x%02x", - doc::rgba_getr(color), - doc::rgba_getg(color), - doc::rgba_getb(color), - doc::rgba_geta(color)); + buf = fmt::format("#{:02x}{:02x}{:02x}{:02x}", + doc::rgba_getr(color), + doc::rgba_getg(color), + doc::rgba_getb(color), + doc::rgba_geta(color)); } return buf; } diff --git a/src/app/file/file_tests.cpp b/src/app/file/file_tests.cpp index f888f99ff..0963cd4c4 100644 --- a/src/app/file/file_tests.cpp +++ b/src/app/file/file_tests.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2019 Igara Studio S.A. +// Copyright (C) 2018-2023 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -15,6 +15,7 @@ #include "base/base64.h" #include "doc/doc.h" #include "doc/user_data.h" +#include "fmt/format.h" #include #include @@ -27,18 +28,18 @@ using namespace app; TEST(File, SeveralSizes) { // Register all possible image formats. - std::vector fn(256); + std::string fn; app::Context ctx; for (int w=10; w<=10+503*2; w+=503) { for (int h=10; h<=10+503*2; h+=503) { - //std::sprintf(&fn[0], "test_%dx%d.ase", w, h); - std::sprintf(&fn[0], "test.ase"); + //fn = fmt::format("test_{}x{}.ase", w, h); + fn = "test.ase"; { std::unique_ptr doc( ctx.documents().add(w, h, doc::ColorMode::INDEXED, 256)); - doc->setFilename(&fn[0]); + doc->setFilename(fn); // Random pixels Layer* layer = doc->sprite()->root()->firstLayer(); @@ -59,7 +60,7 @@ TEST(File, SeveralSizes) } { - std::unique_ptr doc(load_document(&ctx, &fn[0])); + std::unique_ptr doc(load_document(&ctx, fn)); ASSERT_EQ(w, doc->sprite()->width()); ASSERT_EQ(h, doc->sprite()->height()); diff --git a/src/app/filename_formatter.cpp b/src/app/filename_formatter.cpp index a17a77bdc..cb0f7fff9 100644 --- a/src/app/filename_formatter.cpp +++ b/src/app/filename_formatter.cpp @@ -16,6 +16,7 @@ #include "base/convert_to.h" #include "base/fs.h" #include "base/replace_string.h" +#include "fmt/format.h" #include #include @@ -35,14 +36,17 @@ static bool replace_frame(const char* frameKey, // E.g. = "{frame" if (j != std::string::npos) { std::string from = str.substr(i, j - i + 1); if (frameBase >= 0) { - std::vector to(32); int offset = std::strtol(from.c_str()+keyLen, NULL, 10); - std::sprintf(&to[0], "%0*d", (int(j)-int(i+keyLen)), frameBase + offset); - base::replace_string(str, from, &to[0]); + const std::string to = + fmt::format("{0:0{1}d}", + frameBase + offset, + (int(j)-int(i+keyLen))); + + base::replace_string(str, from, to); } else - base::replace_string(str, from, ""); + base::replace_string(str, from, std::string()); } return true; } @@ -59,9 +63,7 @@ static bool autodetect_frame_format(const std::string& filename, int frameWidth = 0; frameBase = split_filename(filename, left, right, frameWidth); if (frameBase >= 0) { - std::vector buf(32); - std::sprintf(&buf[0], "{frame%0*d}", frameWidth, frameBase); - frameFormat = std::string(&buf[0]); + frameFormat = fmt::format("{{frame{0:0{1}d}}}", frameBase, frameWidth); return true; } else diff --git a/src/app/ini_file.cpp b/src/app/ini_file.cpp index c6022b57e..ddb3f8442 100644 --- a/src/app/ini_file.cpp +++ b/src/app/ini_file.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2018-2021 Igara Studio S.A. +// Copyright (C) 2018-2023 Igara Studio S.A. // Copyright (C) 2001-2016 David Capello // // This program is distributed under the terms of @@ -16,6 +16,7 @@ #include "base/split_string.h" #include "base/string.h" #include "cfg/cfg.h" +#include "fmt/format.h" #ifdef __APPLE__ #include "os/logger.h" @@ -208,9 +209,8 @@ Point get_config_point(const char* section, const char* name, const Point& point void set_config_point(const char* section, const char* name, const Point& point) { - char buf[128]; - sprintf(buf, "%d %d", point.x, point.y); - set_config_string(section, name, buf); + std::string buf = fmt::format("{} {}", point.x, point.y); + set_config_string(section, name, buf.c_str()); } Size get_config_size(const char* section, const char* name, const Size& size) @@ -230,9 +230,8 @@ Size get_config_size(const char* section, const char* name, const Size& size) void set_config_size(const char* section, const char* name, const Size& size) { - char buf[128]; - sprintf(buf, "%d %d", size.w, size.h); - set_config_string(section, name, buf); + std::string buf = fmt::format("{} {}", size.w, size.h); + set_config_string(section, name, buf.c_str()); } Rect get_config_rect(const char* section, const char* name, const Rect& rect) @@ -254,9 +253,8 @@ Rect get_config_rect(const char* section, const char* name, const Rect& rect) void set_config_rect(const char* section, const char* name, const Rect& rect) { - char buf[128]; - sprintf(buf, "%d %d %d %d", rect.x, rect.y, rect.w, rect.h); - set_config_string(section, name, buf); + std::string buf = fmt::format("{} {} {} {}", rect.x, rect.y, rect.w, rect.h); + set_config_string(section, name, buf.c_str()); } app::Color get_config_color(const char* section, const char* name, const app::Color& value) diff --git a/src/app/resource_finder.cpp b/src/app/resource_finder.cpp index ef056bf5d..3a3126c6c 100644 --- a/src/app/resource_finder.cpp +++ b/src/app/resource_finder.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2021 Igara Studio S.A. +// Copyright (C) 2019-2023 Igara Studio S.A. // Copyright (C) 2001-2016 David Capello // // This program is distributed under the terms of @@ -89,31 +89,31 @@ void ResourceFinder::includeDataDir(const char* filename) #ifdef _WIN32 - sprintf(buf, "data/%s", filename); + std::snprintf(buf, sizeof(buf), "data/%s", filename); includeHomeDir(buf); // %AppData%/Aseprite/data/filename includeBinDir(buf); // $BINDIR/data/filename #elif __APPLE__ - sprintf(buf, "data/%s", filename); + std::snprintf(buf, sizeof(buf), "data/%s", filename); includeUserDir(buf); // $HOME/Library/Application Support/Aseprite/data/filename includeBinDir(buf); // $BINDIR/data/filename (outside the bundle) - sprintf(buf, "../Resources/data/%s", filename); + std::snprintf(buf, sizeof(buf), "../Resources/data/%s", filename); includeBinDir(buf); // $BINDIR/../Resources/data/filename (inside a bundle) #else // $HOME/.config/aseprite/filename - sprintf(buf, "aseprite/data/%s", filename); + std::snprintf(buf, sizeof(buf), "aseprite/data/%s", filename); includeHomeConfigDir(buf); // $BINDIR/data/filename - sprintf(buf, "data/%s", filename); + std::snprintf(buf, sizeof(buf), "data/%s", filename); includeBinDir(buf); // $BINDIR/../share/aseprite/data/filename (installed in /usr/ or /usr/local/) - sprintf(buf, "../share/aseprite/data/%s", filename); + std::snprintf(buf, sizeof(buf), "../share/aseprite/data/%s", filename); includeBinDir(buf); #endif @@ -139,7 +139,7 @@ void ResourceFinder::includeHomeDir(const char* filename) if ((env) && (*env)) { // $HOME/filename - sprintf(buf, "%s/%s", env, filename); + std::snprintf(buf, sizeof(buf), "%s/%s", env, filename); addPath(buf); } else { diff --git a/src/app/shade.cpp b/src/app/shade.cpp index 36a494e6f..b08840fa8 100644 --- a/src/app/shade.cpp +++ b/src/app/shade.cpp @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2023 Igara Studio S.A. // Copyright (C) 2001-2015 David Capello // // This program is distributed under the terms of @@ -31,8 +32,9 @@ std::string shade_to_string(const Shade& shade) { std::string res; for (const auto& s : shade) { + if (!res.empty()) + res += " "; res += s.toString(); - res += " "; } return res; } diff --git a/src/app/tools/controllers.h b/src/app/tools/controllers.h index 048f62d6a..73ab52ccb 100644 --- a/src/app/tools/controllers.h +++ b/src/app/tools/controllers.h @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2019-2022 Igara Studio S.A. +// Copyright (C) 2019-2023 Igara Studio S.A. // Copyright (C) 2001-2018 David Capello // // This program is distributed under the terms of @@ -8,6 +8,7 @@ #include "app/snap_to_grid.h" #include "base/gcd.h" #include "base/pi.h" +#include "fmt/format.h" #include #include @@ -93,13 +94,12 @@ public: return; gfx::Point offset = loop->statusBarPositionOffset(); - char buf[1024]; - sprintf(buf, ":start: %d %d :end: %d %d", - stroke.firstPoint().x+offset.x, - stroke.firstPoint().y+offset.y, - stroke.lastPoint().x+offset.x, - stroke.lastPoint().y+offset.y); - text = buf; + text = fmt::format( + ":start: {} {} :end: {} {}", + stroke.firstPoint().x+offset.x, + stroke.firstPoint().y+offset.y, + stroke.lastPoint().x+offset.x, + stroke.lastPoint().y+offset.y); } private: @@ -253,16 +253,16 @@ public: if (stroke.size() < 2) return; - int w = ABS(stroke[1].x-stroke[0].x)+1; - int h = ABS(stroke[1].y-stroke[0].y)+1; + const int w = ABS(stroke[1].x-stroke[0].x)+1; + const int h = ABS(stroke[1].y-stroke[0].y)+1; - gfx::Point offset = loop->statusBarPositionOffset(); - char buf[1024]; - int gcd = base::gcd(w, h); - sprintf(buf, ":start: %d %d :end: %d %d :size: %d %d :distance: %.1f", - stroke[0].x+offset.x, stroke[0].y+offset.y, - stroke[1].x+offset.x, stroke[1].y+offset.y, - w, h, std::sqrt(w*w + h*h)); + const gfx::Point offset = loop->statusBarPositionOffset(); + const int gcd = base::gcd(w, h); + + text = fmt::format(":start: {} {} :end: {} {} :size: {} {} :distance: {:.1f}", + stroke[0].x+offset.x, stroke[0].y+offset.y, + stroke[1].x+offset.x, stroke[1].y+offset.y, + w, h, std::sqrt(w*w + h*h)); if (hasAngle() || loop->getIntertwine()->snapByAngle()) { @@ -272,14 +272,12 @@ public: else angle = std::atan2(static_cast(stroke[0].y-stroke[1].y), static_cast(stroke[1].x-stroke[0].x)); - sprintf(buf+strlen(buf), " :angle: %.1f", 180.0 * angle / PI); + text += fmt::format(" :angle: {:.1f}", 180.0 * angle / PI); } // Aspect ratio at the end - sprintf(buf+strlen(buf), " :aspect_ratio: %d:%d", - w/gcd, h/gcd); - - text = buf; + text += fmt::format(" :aspect_ratio: {}:{}", + w/gcd, h/gcd); } double getShapeAngle() const override { @@ -361,13 +359,11 @@ public: return; gfx::Point offset = loop->statusBarPositionOffset(); - char buf[1024]; - sprintf(buf, ":start: %d %d :end: %d %d", - stroke.firstPoint().x+offset.x, - stroke.firstPoint().y+offset.y, - stroke.lastPoint().x+offset.x, - stroke.lastPoint().y+offset.y); - text = buf; + text = fmt::format(":start: {} {} :end: {} {}", + stroke.firstPoint().x+offset.x, + stroke.firstPoint().y+offset.y, + stroke.lastPoint().x+offset.x, + stroke.lastPoint().y+offset.y); } }; @@ -401,11 +397,9 @@ public: return; gfx::Point offset = loop->statusBarPositionOffset(); - char buf[1024]; - sprintf(buf, ":pos: %d %d", - stroke[0].x+offset.x, - stroke[0].y+offset.y); - text = buf; + text = fmt::format(":pos: {} {}", + stroke[0].x+offset.x, + stroke[0].y+offset.y); } }; @@ -459,14 +453,12 @@ public: return; gfx::Point offset = loop->statusBarPositionOffset(); - char buf[1024]; - sprintf(buf, ":start: %d %d :end: %d %d (%d %d - %d %d)", - stroke[0].x+offset.x, stroke[0].y+offset.y, - stroke[3].x+offset.x, stroke[3].y+offset.y, - stroke[1].x+offset.x, stroke[1].y+offset.y, - stroke[2].x+offset.x, stroke[2].y+offset.y); - text = buf; + text = fmt::format(":start: {} {} :end: {} {} ({} {} - {} {})", + stroke[0].x+offset.x, stroke[0].y+offset.y, + stroke[3].x+offset.x, stroke[3].y+offset.y, + stroke[1].x+offset.x, stroke[1].y+offset.y, + stroke[2].x+offset.x, stroke[2].y+offset.y); } private: diff --git a/src/app/ui/context_bar.cpp b/src/app/ui/context_bar.cpp index 1b22d4d0f..5afeccf2f 100644 --- a/src/app/ui/context_bar.cpp +++ b/src/app/ui/context_bar.cpp @@ -654,12 +654,13 @@ private: m_loaded = true; - char buf[32]; + std::string buf; int n = get_config_int("shades", "count", 0); n = std::clamp(n, 0, 256); for (int i=0; i= 2) m_shades.push_back(shade); } @@ -669,12 +670,13 @@ private: if (!m_loaded) return; - char buf[32]; + std::string buf; int n = int(m_shades.size()); set_config_int("shades", "count", n); for (int i=0; iviewportBounds(); - char buf[128]; - sprintf(buf, "%c %.4gs", - Preferences::instance().experimental.newRenderEngine() ? 'N': 'O', - renderElapsed); + std::string buf = + fmt::format("{:c} {:.4g}s", + Preferences::instance().experimental.newRenderEngine() ? 'N': 'O', + renderElapsed); g->drawText( buf, gfx::rgba(255, 255, 255, 255), diff --git a/src/app/ui/timeline/timeline.cpp b/src/app/ui/timeline/timeline.cpp index 28b27045e..131dd7459 100644 --- a/src/app/ui/timeline/timeline.cpp +++ b/src/app/ui/timeline/timeline.cpp @@ -3746,7 +3746,7 @@ void Timeline::updateStatusBarForFrame(const frame_t frame, if (!m_sprite) return; - char buf[256] = { 0 }; + std::string buf; frame_t base = docPref().timeline.firstFrame(); frame_t firstFrame = frame; frame_t lastFrame = frame; @@ -3761,41 +3761,34 @@ void Timeline::updateStatusBarForFrame(const frame_t frame, lastFrame = m_range.lastFrame(); } - std::sprintf( - buf+std::strlen(buf), ":frame: %d", - base+frame); + buf += fmt::format(":frame: {}", + int(base+frame)); if (firstFrame != lastFrame) { - std::sprintf( - buf+std::strlen(buf), " [%d...%d]", - int(base+firstFrame), - int(base+lastFrame)); + buf += fmt::format(" [{}...{}]", + int(base+firstFrame), + int(base+lastFrame)); } - std::sprintf( - buf+std::strlen(buf), " :clock: %s", - human_readable_time(m_sprite->frameDuration(frame)).c_str()); + buf += fmt::format(" :clock: {}", + human_readable_time(m_sprite->frameDuration(frame))); if (firstFrame != lastFrame) { - std::sprintf( - buf+std::strlen(buf), " [%s]", - tag ? - human_readable_time(tagFramesDuration(tag)).c_str(): - human_readable_time(selectedFramesDuration()).c_str()); + buf += fmt::format(" [{}]", + tag ? + human_readable_time(tagFramesDuration(tag)): + human_readable_time(selectedFramesDuration())); } if (m_sprite->totalFrames() > 1) - std::sprintf( - buf+std::strlen(buf), "/%s", - human_readable_time(m_sprite->totalAnimationDuration()).c_str()); + buf += fmt::format("/{}", + human_readable_time(m_sprite->totalAnimationDuration())); if (cel) { - std::sprintf( - buf+std::strlen(buf), " Cel :pos: %d %d :size: %d %d", - cel->bounds().x, cel->bounds().y, - cel->bounds().w, cel->bounds().h); + buf += fmt::format(" Cel :pos: {} {} :size: {} {}", + cel->bounds().x, cel->bounds().y, + cel->bounds().w, cel->bounds().h); if (cel->links() > 0) { - std::sprintf( - buf+std::strlen(buf), " Links %d", - int(cel->links())); + buf += fmt::format(" Links {}", + int(cel->links())); } } diff --git a/src/app/ui/zoom_entry.cpp b/src/app/ui/zoom_entry.cpp index 916ad8875..e3fe2b12b 100644 --- a/src/app/ui/zoom_entry.cpp +++ b/src/app/ui/zoom_entry.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2021 Igara Studio S.A. +// Copyright (C) 2021-2023 Igara Studio S.A. // Copyright (C) 2001-2017 David Capello // // This program is distributed under the terms of @@ -13,6 +13,7 @@ #include "app/modules/gui.h" #include "base/scoped_value.h" +#include "fmt/format.h" #include "gfx/rect.h" #include "gfx/region.h" #include "ui/manager.h" @@ -65,10 +66,7 @@ void ZoomEntry::onValueChange() std::string ZoomEntry::onGetTextFromValue(int value) { render::Zoom zoom = render::Zoom::fromLinearScale(value); - - char buf[256]; - std::sprintf(buf, "%.1f", zoom.scale() * 100.0); - return buf; + return fmt::format("{:.1f}", zoom.scale() * 100.0); } int ZoomEntry::onGetValueFromText(const std::string& text) diff --git a/src/app/util/readable_time.cpp b/src/app/util/readable_time.cpp index 363613c54..db487199e 100644 --- a/src/app/util/readable_time.cpp +++ b/src/app/util/readable_time.cpp @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2023 Igara Studio S.A. // Copyright (C) 2017 David Capello // // This program is distributed under the terms of @@ -10,22 +11,20 @@ #include "app/util/readable_time.h" -#include +#include "fmt/format.h" namespace app { std::string human_readable_time(const int t) { - char buf[32]; if (t < 900) - std::sprintf(buf, "%dms", t); + return fmt::format("{:d}ms", t); else if (t < 1000*59) - std::sprintf(buf, "%0.2fs", double(t) / 1000.0); + return fmt::format("{:0.2f}s", double(t) / 1000.0); else if (t < 1000*60*59) - std::sprintf(buf, "%0.2fm", double(t) / 1000.0 / 60.0); + return fmt::format("{:0.2f}m", double(t) / 1000.0 / 60.0); else - std::sprintf(buf, "%0.2fh", double(t) / 1000.0 / 60.0 / 60.0); - return buf; + return fmt::format("{:0.2f}h", double(t) / 1000.0 / 60.0 / 60.0); } } // namespace app diff --git a/src/app/xml_exception.cpp b/src/app/xml_exception.cpp index 21dec2269..9aee17ed4 100644 --- a/src/app/xml_exception.cpp +++ b/src/app/xml_exception.cpp @@ -1,4 +1,5 @@ // Aseprite +// Copyright (C) 2023 Igara Studio S.A. // Copyright (C) 2001-2015 David Capello // // This program is distributed under the terms of @@ -10,22 +11,18 @@ #include "app/xml_exception.h" +#include "fmt/format.h" #include "tinyxml.h" -#include - namespace app { XmlException::XmlException(const TiXmlDocument* doc) throw() { try { - char buf[4096]; // TODO Overflow - - sprintf(buf, "Error in XML file '%s' (line %d, column %d)\nError %d: %s", - doc->Value(), doc->ErrorRow(), doc->ErrorCol(), - doc->ErrorId(), doc->ErrorDesc()); - - setMessage(buf); + setMessage( + fmt::format("Error in XML file '{}' (line {}, column {})\nError {}: {}", + doc->Value(), doc->ErrorRow(), doc->ErrorCol(), + doc->ErrorId(), doc->ErrorDesc()).c_str()); } catch (...) { // No throw diff --git a/src/ui/alert.cpp b/src/ui/alert.cpp index 6bab0e458..0c611649c 100644 --- a/src/ui/alert.cpp +++ b/src/ui/alert.cpp @@ -121,7 +121,7 @@ void Alert::addButton(const std::string& text) m_buttons.push_back(button); char id[256]; - sprintf(id, "button-%lu", m_buttons.size()); + std::snprintf(id, sizeof(id), "button-%lu", m_buttons.size()); button->setId(id); button->Click.connect([this, button]{ closeWindow(button); }); diff --git a/src/ui/entry.cpp b/src/ui/entry.cpp index b70311b50..00a5f78eb 100644 --- a/src/ui/entry.cpp +++ b/src/ui/entry.cpp @@ -60,7 +60,7 @@ Entry::Entry(const int maxsize, const char* format, ...) if (format) { va_list ap; va_start(ap, format); - vsprintf(buf, format, ap); + std::vsnprintf(buf, sizeof(buf), format, ap); va_end(ap); } // empty string diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp index a6c0bf014..5dbe1d4e9 100644 --- a/src/ui/slider.cpp +++ b/src/ui/slider.cpp @@ -74,7 +74,7 @@ std::string Slider::convertValueToText(int value) const return m_delegate->onGetTextFromValue(value); else { char buf[128]; - std::sprintf(buf, "%d", value); + std::snprintf(buf, sizeof(buf), "%d", value); return buf; } } diff --git a/src/ui/widget.cpp b/src/ui/widget.cpp index acfe8aa75..7095f1db0 100644 --- a/src/ui/widget.cpp +++ b/src/ui/widget.cpp @@ -144,7 +144,7 @@ void Widget::setTextf(const char *format, ...) va_list ap; va_start(ap, format); char buf[4096]; - vsprintf(buf, format, ap); + std::vsnprintf(buf, sizeof(buf), format, ap); va_end(ap); setText(buf);