Skip to content

Commit

Permalink
Use snprintf instead of printf
Browse files Browse the repository at this point in the history
Also avoid raw new/deletes and use a std::string instead to hold the
result of the formatting operation.

Signed-off-by: Rodrigo Tobar <[email protected]>
  • Loading branch information
rtobar committed Jul 10, 2024
1 parent 5f89d3e commit ef8d72f
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/apps/profit-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ void show_version(std::ostream &os) {
os << endl;
}

static const char *help_msg = R"===(
static const char *help_msg_fmt = R"===(
%s: utility program to generate an image out of a model and a set of profiles
This program is licensed under the GPLv3 license.
Expand Down Expand Up @@ -247,10 +247,10 @@ For more information visit https://libprofit.readthedocs.io.
template <typename T>
static
void usage(std::basic_ostream<T> &os, char *prog_name) {
char *buff = new char[std::strlen(help_msg) - 4 + std::strlen(prog_name) * 2 + 1];
std::sprintf(buff, help_msg, prog_name, prog_name);
std::size_t bufsize = std::strlen(help_msg_fmt) - 4 + std::strlen(prog_name) * 2;
std::string buff(bufsize, 0);
std::snprintf(&buff[0], bufsize, help_msg_fmt, prog_name, prog_name);
os << buff;
delete []buff;
}

static
Expand Down

0 comments on commit ef8d72f

Please sign in to comment.