From 7f5ea145e9faed56bea1ed11e0f41828a4f71cda Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Thu, 8 Jul 2021 17:29:14 +0200 Subject: [PATCH] Fix MSVC C4477 warning Also take translation in to account when printing XP info --- Source/qol/common.cpp | 7 ++++--- Source/qol/common.h | 2 +- Source/qol/xpbar.cpp | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Source/qol/common.cpp b/Source/qol/common.cpp index 11c9184f7..93e178802 100644 --- a/Source/qol/common.cpp +++ b/Source/qol/common.cpp @@ -11,17 +11,18 @@ #include "engine/render/text_render.hpp" #include "qol/monhealthbar.h" #include "qol/xpbar.h" +#include "utils/language.h" namespace devilution { -char *PrintWithSeparator(char *out, int64_t n) +char *PrintWithSeparator(char *out, int n) { if (n < 1000) { - return out + sprintf(out, "%ld", n); + return out + sprintf(out, "%d", n); } char *append = PrintWithSeparator(out, n / 1000); - return append + sprintf(append, ",%03ld", n % 1000); + return append + sprintf(append, _(/* TRANSLATORS: Decimal separator */ ",%03d"), n % 1000); } void FreeQol() diff --git a/Source/qol/common.h b/Source/qol/common.h index 167cd6c67..3d455d45c 100644 --- a/Source/qol/common.h +++ b/Source/qol/common.h @@ -17,7 +17,7 @@ struct Surface; * @param n Number to print * @return Address of first character after printed number */ -char *PrintWithSeparator(char *out, int64_t n); +char *PrintWithSeparator(char *out, int n); void FreeQol(); void InitQol(); diff --git a/Source/qol/xpbar.cpp b/Source/qol/xpbar.cpp index 93abf3031..4ddfd00a2 100644 --- a/Source/qol/xpbar.cpp +++ b/Source/qol/xpbar.cpp @@ -133,7 +133,7 @@ bool CheckXPBarInfo() infoclr = UIS_GOLD; strcpy(tempstr, _("Experience: ")); - PrintWithSeparator(tempstr + SDL_arraysize("Experience: ") - 1, ExpLvlsTbl[charLevel - 1]); + PrintWithSeparator(tempstr + strlen(tempstr), ExpLvlsTbl[charLevel - 1]); AddPanelString(tempstr); AddPanelString(_("Maximum Level")); @@ -144,11 +144,11 @@ bool CheckXPBarInfo() infoclr = UIS_SILVER; strcpy(tempstr, _("Experience: ")); - PrintWithSeparator(tempstr + SDL_arraysize("Experience: ") - 1, player._pExperience); + PrintWithSeparator(tempstr + strlen(tempstr), player._pExperience); AddPanelString(tempstr); strcpy(tempstr, _("Next Level: ")); - PrintWithSeparator(tempstr + SDL_arraysize("Next Level: ") - 1, ExpLvlsTbl[charLevel]); + PrintWithSeparator(tempstr + strlen(tempstr), ExpLvlsTbl[charLevel]); AddPanelString(tempstr); strcpy(PrintWithSeparator(tempstr, ExpLvlsTbl[charLevel] - player._pExperience), fmt::format(_(" to Level {:d}"), charLevel + 1).c_str());