From 3be3d993576fbce97cfa6068e427334deb5feb96 Mon Sep 17 00:00:00 2001 From: Joel Kronqvist Date: Sun, 21 Apr 2024 18:34:15 +0300 Subject: Minor fixes --- config-parser.c | 25 ++++++++----------------- formatting.c | 8 ++++---- stdu.c | 1 - 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/config-parser.c b/config-parser.c index 0ef0a47..e10275f 100644 --- a/config-parser.c +++ b/config-parser.c @@ -166,8 +166,7 @@ Result parse_config(int argc, char* argv[]) { snprintf( error_msg, 53, - "the precision may not contain non-numeric characters", - precision + "the precision may not contain non-numeric characters" ); res.result = error_msg; return res; @@ -184,7 +183,7 @@ Result parse_config(int argc, char* argv[]) { } } - Config* conf = malloc(sizeof(int) + sizeof(bool)); + Config* conf = malloc(sizeof(Config)); conf->help = tmp.help; conf->human_readable = tmp.human_readable; conf->multiline = tmp.multiline; @@ -246,15 +245,11 @@ char* test_precision_parsing() { } char* test_human_readability_parsing() { - int argc; - Result res; - Config* conf; - char* error_msg; - - argc = 2; + int argc = 2; char* argv[] = { "stdu", "--human-readable" }; - res = parse_config(argc, argv); - conf = (Config*) res.result; + Result res = parse_config(argc, argv); + Config* conf = (Config*) res.result; + mt_assert_eq(res.success, true); mt_assert_eq(conf->human_readable, true); free(conf); @@ -263,14 +258,10 @@ char* test_human_readability_parsing() { } char* test_multioption_parsing() { - Result res; - Config* conf; - char* error_msg; - int argc = 3; char* argv[] = { "stdu", "-mh?p", "3"}; - res = parse_config(argc, argv); - conf = (Config*) res.result; + Result res = parse_config(argc, argv); + Config* conf = (Config*) res.result; mt_assert_eq(res.success, true); mt_assert_eq(conf->help, true); mt_assert_eq(conf->human_readable, true); diff --git a/formatting.c b/formatting.c index ac0222c..60f37ee 100644 --- a/formatting.c +++ b/formatting.c @@ -273,7 +273,7 @@ char* test_floored_exponent_notation() { exp_notated res = ull_floored_exponent_notation(9489345, 3); snprintf(msg, bufsize, - "ull_floored_exponent_notation(9489345, 3): expected 948*10^4, got %d*%d^%d", + "ull_floored_exponent_notation(9489345, 3): expected 948*10^4, got %llu*%d^%d", res.mantissa, res.base, res.exponent ); mt_assert( @@ -284,7 +284,7 @@ char* test_floored_exponent_notation() { res = ull_floored_exponent_notation_base(3145733, 1, 1024); snprintf(msg, bufsize, - "ull_floored_exponent_notation_base(3145733, 1, 1024): expected 3*1024^2, got %d*%d^%d", + "ull_floored_exponent_notation_base(3145733, 1, 1024): expected 3*1024^2, got %llu*%d^%d", res.mantissa, res.base, res.exponent ); mt_assert( @@ -303,7 +303,7 @@ char* test_ceiled_exponent_notation() { exp_notated res = ull_ceiled_exponent_notation(9489345, 3); snprintf(msg, bufsize, - "ull_ceiled_exponent_notation(9489345, 3): expected 949*10^4, got %d*%d^%d", + "ull_ceiled_exponent_notation(9489345, 3): expected 949*10^4, got %llu*%d^%d", res.mantissa, res.base, res.exponent ); mt_assert( @@ -314,7 +314,7 @@ char* test_ceiled_exponent_notation() { res = ull_ceiled_exponent_notation_base(3145733, 1, 1024); snprintf(msg, bufsize, - "ull_ceiled_exponent_notation_base(3145733, 1, 1024): expected 4*1024^2, got %d*%d^%d", + "ull_ceiled_exponent_notation_base(3145733, 1, 1024): expected 4*1024^2, got %llu*%d^%d", res.mantissa, res.base, res.exponent ); mt_assert( diff --git a/stdu.c b/stdu.c index a41071a..2cd0aa4 100644 --- a/stdu.c +++ b/stdu.c @@ -72,7 +72,6 @@ Print amount of data piped to stdin.\n\ - bytes_read; bufsize = 1024; } - size_t max_bufsize = 1048576; char* buf = malloc(bufsize); char* tmpbuf; -- cgit v1.2.3