summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan Neulinger <nneul@neulinger.org>2023-03-15 09:54:53 -0500
committerGitHub <noreply@github.com>2023-03-15 09:54:53 -0500
commit86b3a47355078c4537db08130c1c90d828c1f2ed (patch)
treec189f16033d8b0377eeb2f7aa623b4baf9604d66 /src
parent221edd497f444af415e3767e5cd6ad3f9a8fa849 (diff)
parent61afdd35ffc9478fe9cba2d0a3a575ec9004136b (diff)
downloadcracklib-86b3a47355078c4537db08130c1c90d828c1f2ed.tar.gz
Merge pull request #51 from yixiangzhike/master
Fix an issue that all words are deleted when there is no valid input data
Diffstat (limited to 'src')
-rw-r--r--src/util/packer.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/util/packer.c b/src/util/packer.c
index e3f9500..be6fbf5 100644
--- a/src/util/packer.c
+++ b/src/util/packer.c
@@ -22,6 +22,7 @@ main(argc, argv)
PWDICT *pwp;
char buffer[STRINGSIZE], prev[STRINGSIZE];
char *file;
+ char opened = 0;
if (argc <= 1)
{
@@ -39,12 +40,6 @@ main(argc, argv)
return (-1);
}
- if (!(pwp = PWOpen(file, "w")))
- {
- perror(file);
- return (-1);
- }
-
wrote = 0;
prev[0] = '\0';
@@ -62,6 +57,16 @@ main(argc, argv)
continue;
}
+ if (!opened)
+ {
+ if (!(pwp = PWOpen(file, "w")))
+ {
+ perror(file);
+ return (-1);
+ }
+ opened = 1;
+ }
+
/*
* If this happens, strcmp() in FindPW() in packlib.c will be unhappy.
*/
@@ -79,7 +84,8 @@ main(argc, argv)
wrote++;
}
- PWClose(pwp);
+ if (opened)
+ PWClose(pwp);
printf("%lu %lu\n", readed, wrote);