From 332983c97b7a729c4dc5f19aa9ee4a22c420f7d8 Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Tue, 27 Jun 2023 20:23:44 +1000 Subject: The Formatting String Catastrophe --- source/json_tool/json_tool.cpp | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'source/json_tool/json_tool.cpp') diff --git a/source/json_tool/json_tool.cpp b/source/json_tool/json_tool.cpp index 13c2200..4ea5b05 100644 --- a/source/json_tool/json_tool.cpp +++ b/source/json_tool/json_tool.cpp @@ -53,12 +53,12 @@ String Star::reprWithLineEnding(FormattedJson const& json) { // unix. String repr = json.repr(); if (repr.contains("\r")) - return strf("%s\r\n", repr); - return strf("%s\n", repr); + return strf("{}\r\n", repr); + return strf("{}\n", repr); } void OutputOnSeparateLines::out(FormattedJson const& json) { - coutf("%s", reprWithLineEnding(json)); + coutf("{}", reprWithLineEnding(json)); } void OutputOnSeparateLines::flush() {} @@ -73,7 +73,7 @@ void ArrayOutput::flush() { for (FormattedJson const& result : m_results) { array = array.append(result); } - coutf("%s", reprWithLineEnding(array)); + coutf("{}", reprWithLineEnding(array)); } FormattedJson Star::addOrSet(bool add, @@ -140,7 +140,7 @@ void forEachChild(FormattedJson const& parent, function parseArgs(int argc, char** argv) { } else { if (!File::exists(arg)) { - cerrf("File %s doesn't exist\n", arg); + cerrf("File {} doesn't exist\n", arg); return {}; } parsed.inputs.append(FileInput{arg}); @@ -415,23 +415,23 @@ int main(int argc, char** argv) { Maybe parsedArgs = parseArgs(argc, argv); if (!parsedArgs) { - cerrf("Usage: %s [--get ] (-j | *)\n", argv[0]); + cerrf("Usage: {} [--get ] (-j | *)\n", argv[0]); cerrf( - "Usage: %s --set [-i] [(--at (beginning|end) | --before | --after )] (-j " + "Usage: {} --set [-i] [(--at (beginning|end) | --before | --after )] (-j " " | *)\n", argv[0]); cerrf( - "Usage: %s --add [-i] [(--at (beginning|end) | --before | --after )] (-j " + "Usage: {} --add [-i] [(--at (beginning|end) | --before | --after )] (-j " " | *)\n", argv[0]); cerrf( - "Usage: %s --edit [(--at (beginning|end) | --before | --after )] [--input " + "Usage: {} --edit [(--at (beginning|end) | --before | --after )] [--input " "(csv|json|string)] +\n", argv[0]); cerrf("\n"); - cerrf("Example: %s --get /dialog/0/message guard.npctype\n", argv[0]); - cerrf("Example: %s --get 'foo[0]' -j '{\"foo\":[0,1,2,3]}'\n", argv[0]); - cerrf("Example: %s --edit /tags --input csv --find ../assets/ .object\n", argv[0]); + cerrf("Example: {} --get /dialog/0/message guard.npctype\n", argv[0]); + cerrf("Example: {} --get 'foo[0]' -j '{\"foo\":[0,1,2,3]}'\n", argv[0]); + cerrf("Example: {} --edit /tags --input csv --find ../assets/ .object\n", argv[0]); return 1; } @@ -457,15 +457,15 @@ int main(int argc, char** argv) { return 0; } catch (JsonParsingException const& e) { - cerrf("%s\n", e.what()); + cerrf("{}\n", e.what()); return 1; } catch (JsonException const& e) { - cerrf("%s\n", e.what()); + cerrf("{}\n", e.what()); return 1; } catch (std::exception const& e) { - cerrf("Exception caught: %s\n", outputException(e, true)); + cerrf("Exception caught: {}\n", outputException(e, true)); return 1; } } -- cgit v1.2.3