From e372b4dc1142e70b41d55eb157cc137dfd218373 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Feb 2020 01:14:11 +1300 Subject: Add const decorators --- crypt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crypt.c b/crypt.c index 4c9f0fb..3ebcbb3 100644 --- a/crypt.c +++ b/crypt.c @@ -5,12 +5,12 @@ #include /* strerror(3) */ #include /* crypt(3) */ -void error(char *); +void error(const char *); void usage(FILE *, int); int main (int argc, char **argv) { - char *hash, *key, *salt; + const char *hash, *key, *salt; int opt; while ((opt = getopt(argc, argv, "h")) != -1) { @@ -52,7 +52,7 @@ int main (int argc, char **argv) /* * Exit with error error message */ -void error(char *message) +void error(const char *message) { fprintf(stderr, "%s\n", message); exit(EXIT_FAILURE); @@ -61,7 +61,7 @@ void error(char *message) /* * Show usage to given stream, and exit with given code */ -void usage(FILE *stream, int status) +void usage(FILE *stream, const int status) { fputs("USAGE: crypt [-h | KEY SALT]\n", stream); exit(status); -- cgit v1.2.3 From a933cf4be7bd594fb5360cfe8f09e01e86b23ae1 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Feb 2020 01:14:38 +1300 Subject: Check print success more comprehensively --- crypt.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/crypt.c b/crypt.c index 3ebcbb3..86e8fce 100644 --- a/crypt.c +++ b/crypt.c @@ -1,4 +1,5 @@ #define _XOPEN_SOURCE +#include #include #include #include @@ -11,7 +12,7 @@ void usage(FILE *, int); int main (int argc, char **argv) { const char *hash, *key, *salt; - int opt; + int opt, printed; while ((opt = getopt(argc, argv, "h")) != -1) { switch (opt) { @@ -44,8 +45,16 @@ int main (int argc, char **argv) if (!(hash = crypt(key, salt))) { error(strerror(errno)); } + assert(strlen(hash) > 0); + + /* + * Print the hash, and ensure we printed all of it + */ + if ((printed = printf("%s\n", hash)) < 0) { + error(strerror(errno)); + } + assert(printed == strlen(hash) + 1); - puts(hash); exit(EXIT_SUCCESS); } -- cgit v1.2.3 From 64c823916d060647dc6b3e91d21f48063f15c16f Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Feb 2020 01:14:54 +1300 Subject: Correct an error message --- crypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypt.c b/crypt.c index 86e8fce..18b33e9 100644 --- a/crypt.c +++ b/crypt.c @@ -59,7 +59,7 @@ int main (int argc, char **argv) } /* - * Exit with error error message + * Exit with error message and status */ void error(const char *message) { -- cgit v1.2.3 From 85a3ed3aff7430b4231797466a7d4589426e732a Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Feb 2020 01:15:25 +1300 Subject: Remove stray space after function name --- crypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypt.c b/crypt.c index 18b33e9..8572199 100644 --- a/crypt.c +++ b/crypt.c @@ -9,7 +9,7 @@ void error(const char *); void usage(FILE *, int); -int main (int argc, char **argv) +int main(int argc, char **argv) { const char *hash, *key, *salt; int opt, printed; -- cgit v1.2.3 From 9c30a8423dea749f8959ec03def4a8396c430b91 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Feb 2020 01:26:45 +1300 Subject: Use a manual check in lieu of an assert --- crypt.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crypt.c b/crypt.c index 8572199..c30672f 100644 --- a/crypt.c +++ b/crypt.c @@ -53,7 +53,9 @@ int main(int argc, char **argv) if ((printed = printf("%s\n", hash)) < 0) { error(strerror(errno)); } - assert(printed == strlen(hash) + 1); + if (printed != strlen(hash) + 1) { /* +1 for newline */ + error("Incomplete print"); + } exit(EXIT_SUCCESS); } -- cgit v1.2.3 From c4b4ac4c075d498c2ca3606ee920407a4d556b52 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Feb 2020 01:30:30 +1300 Subject: Cast variable for comparison --- crypt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crypt.c b/crypt.c index c30672f..592869e 100644 --- a/crypt.c +++ b/crypt.c @@ -53,7 +53,7 @@ int main(int argc, char **argv) if ((printed = printf("%s\n", hash)) < 0) { error(strerror(errno)); } - if (printed != strlen(hash) + 1) { /* +1 for newline */ + if ((unsigned) printed < strlen(hash) + 1) { /* +1 for newline */ error("Incomplete print"); } -- cgit v1.2.3 From 90498a10794218213d6aa978a6dd93cd8d50808c Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Feb 2020 01:33:09 +1300 Subject: Check zero print --- crypt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/crypt.c b/crypt.c index 592869e..48c8bd2 100644 --- a/crypt.c +++ b/crypt.c @@ -53,6 +53,7 @@ int main(int argc, char **argv) if ((printed = printf("%s\n", hash)) < 0) { error(strerror(errno)); } + assert(printed > 0); if ((unsigned) printed < strlen(hash) + 1) { /* +1 for newline */ error("Incomplete print"); } -- cgit v1.2.3 From 592ea1a385699d636c367ae80d9f43c0c11b7644 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Sat, 1 Feb 2020 01:42:42 +1300 Subject: Bump VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 227cea2..7ec1d6d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.0.0 +2.1.0 -- cgit v1.2.3