diff --git a/src/apps/fits_utils.cpp b/src/apps/fits_utils.cpp index 4d31886..019cb53 100644 --- a/src/apps/fits_utils.cpp +++ b/src/apps/fits_utils.cpp @@ -127,7 +127,7 @@ Image from_fits(const std::string &filename, PixelScale &pixel_scale) static void write_header(std::ofstream &f, const char *header) { char hdr[81]; - std::sprintf(hdr, "%-80s", header); + std::snprintf(hdr, 81, "%-80s", header); f.write(hdr, 80); }; @@ -135,7 +135,7 @@ template static void write_header(std::ofstream &f, const char *fmt, Ts&&...values) { char hdr[81]; - std::sprintf(hdr, fmt, std::forward(values)...); + std::snprintf(hdr, 81, fmt, std::forward(values)...); write_header(f, hdr); }; diff --git a/src/apps/profit-cli.cpp b/src/apps/profit-cli.cpp index 2e812d3..967cd2a 100644 --- a/src/apps/profit-cli.cpp +++ b/src/apps/profit-cli.cpp @@ -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. @@ -247,10 +247,10 @@ For more information visit https://libprofit.readthedocs.io. template static void usage(std::basic_ostream &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