aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2020-02-01 01:14:38 +1300
committerTom Ryder <tom@sanctum.geek.nz>2020-02-01 01:14:38 +1300
commita933cf4be7bd594fb5360cfe8f09e01e86b23ae1 (patch)
tree7ed5cd34c341ea640a7af1ad0b49a5325bae3127
parente372b4dc1142e70b41d55eb157cc137dfd218373 (diff)
downloadcrypt-a933cf4be7bd594fb5360cfe8f09e01e86b23ae1.tar.gz
crypt-a933cf4be7bd594fb5360cfe8f09e01e86b23ae1.zip
Check print success more comprehensively
-rw-r--r--crypt.c13
1 files 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 <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);
}