fix sprintf warning

This commit is contained in:
blueloveTH 2024-01-22 13:06:31 +08:00
parent f9616c6ece
commit d077026252

View File

@ -505,15 +505,13 @@ int utf8len(unsigned char c, bool suppress){
char b[32]; char b[32];
if(_precision == -1){ if(_precision == -1){
int prec = std::numeric_limits<f64>::max_digits10-1; int prec = std::numeric_limits<f64>::max_digits10-1;
sprintf(b, "%.*g", prec, val); snprintf(b, sizeof(b), "%.*g", prec, val);
}else{ }else{
int prec = _precision; int prec = _precision;
sprintf(b, "%.*f", prec, val); snprintf(b, sizeof(b), "%.*f", prec, val);
} }
(*this) << b; (*this) << b;
if(std::all_of(b+1, b+strlen(b), isdigit)){ if(std::all_of(b+1, b+strlen(b), isdigit)) (*this) << ".0";
(*this) << ".0";
}
return *this; return *this;
} }