diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2020-02-01 01:14:38 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2020-02-01 01:14:38 +1300 |
commit | a933cf4be7bd594fb5360cfe8f09e01e86b23ae1 (patch) | |
tree | 7ed5cd34c341ea640a7af1ad0b49a5325bae3127 | |
parent | Add const decorators (diff) | |
download | crypt-a933cf4be7bd594fb5360cfe8f09e01e86b23ae1.tar.gz crypt-a933cf4be7bd594fb5360cfe8f09e01e86b23ae1.zip |
Check print success more comprehensively
-rw-r--r-- | crypt.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -1,4 +1,5 @@ #define _XOPEN_SOURCE +#include <assert.h> #include <errno.h> #include <stdio.h> #include <stdlib.h> @@ -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); } |