mirror of
https://github.com/jkriege2/JKQtPlotter.git
synced 2024-12-25 10:01:38 +08:00
Fixed Bug #43: jkqtp_format() had undefined behaviour, because va_start was called with a ref-parameter, which does not work. Now there are 4 overloaded template variants. See https://github.com/jkriege2/JKQtPlotter/issues/43
This commit is contained in:
parent
2b942e1e2d
commit
b22b4ca935
@ -81,15 +81,6 @@ std::string jkqtp_tolower(const std::string& s){
|
||||
return d;
|
||||
};
|
||||
|
||||
std::string jkqtp_format(const std::string& templ, ...){
|
||||
va_list ap;
|
||||
char buffer[4096];
|
||||
va_start (ap, templ);
|
||||
vsnprintf(buffer, 4096, templ.c_str(), ap);
|
||||
va_end (ap);
|
||||
std::string ret(buffer);
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
std::string jkqtp_bytestostr(double bytes){
|
||||
|
@ -89,7 +89,42 @@ JKQTCOMMON_LIB_EXPORT std::string jkqtp_toupper(const std::string& s);
|
||||
/** \brief std::string wrapper around sprintf()
|
||||
* \ingroup jkqtptools_string
|
||||
*/
|
||||
JKQTCOMMON_LIB_EXPORT std::string jkqtp_format(const std::string& templ, ...);
|
||||
template <class T1>
|
||||
inline std::string jkqtp_format(const std::string& templ, T1 d1) {
|
||||
char buffer[4096];
|
||||
snprintf(buffer, 4096, templ.c_str(), d1);
|
||||
return std::string(buffer);
|
||||
};
|
||||
|
||||
/** \brief std::string wrapper around sprintf()
|
||||
* \ingroup jkqtptools_string
|
||||
*/
|
||||
template <class T1, class T2>
|
||||
inline std::string jkqtp_format(const std::string& templ, T1 d1, T2 d2) {
|
||||
char buffer[4096];
|
||||
snprintf(buffer, 4096, templ.c_str(), d1, d2);
|
||||
return std::string(buffer);
|
||||
};
|
||||
|
||||
/** \brief std::string wrapper around sprintf()
|
||||
* \ingroup jkqtptools_string
|
||||
*/
|
||||
template <class T1, class T2, class T3>
|
||||
inline std::string jkqtp_format(const std::string& templ, T1 d1, T2 d2, T3 d3) {
|
||||
char buffer[4096];
|
||||
snprintf(buffer, 4096, templ.c_str(), d1, d2, d3);
|
||||
return std::string(buffer);
|
||||
};
|
||||
|
||||
/** \brief std::string wrapper around sprintf()
|
||||
* \ingroup jkqtptools_string
|
||||
*/
|
||||
template <class T1, class T2, class T3, class T4>
|
||||
inline std::string jkqtp_format(const std::string& templ, T1 d1, T2 d2, T3 d3, T4 d4) {
|
||||
char buffer[4096];
|
||||
snprintf(buffer, 4096, templ.c_str(), d1, d2, d3, d4);
|
||||
return std::string(buffer);
|
||||
};
|
||||
|
||||
/** \brief convert a number of bytes to a string, formatting e.g. 1024 as 1kB, ...
|
||||
* \ingroup jkqtptools_string
|
||||
|
Loading…
Reference in New Issue
Block a user