Skip to content

Commit

Permalink
rewrite getf method
Browse files Browse the repository at this point in the history
  • Loading branch information
pangolp committed Mar 17, 2024
1 parent 7951bea commit c2f0565
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/ASCommon/AzthLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,21 @@ const char * AzthLang::get(uint32 strId, Player const* pl) const
return "Unknown Azth string";
}

const char * AzthLang::getf(uint32 strId, Player const* pl, ...) const
const char* AzthLang::getf(uint32 strId, Player const* pl, ...) const
{
const char *format = get(strId, pl);
const char* format = get(strId, pl);
va_list ap;
char str [2048];
va_start(ap, pl);
vsnprintf(str, 2048, format, ap);
va_end(ap);

const char *ret=&str[0];
va_list ap_copy;
va_copy(ap_copy, ap);
int len = vsnprintf(nullptr, 0, format, ap_copy);
va_end(ap_copy);

std::string result;
result.resize(len + 1);
vsnprintf(&result[0], len + 1, format, ap);
va_end(ap);

return ret;
return result.c_str();
}

0 comments on commit c2f0565

Please sign in to comment.