From afd063a3ce9936f5eb1f5fd00fff6423f782994e Mon Sep 17 00:00:00 2001 From: Nicholas Tay Date: Thu, 13 Jan 2022 23:02:10 +1100 Subject: Fix generation for number params (forgot grammar_size) --- passgen.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/passgen.c b/passgen.c index ee78a89..0b5f754 100644 --- a/passgen.c +++ b/passgen.c @@ -86,20 +86,20 @@ unsigned int get_rng(void) return r; } -char *build_grammar(int triplets, int specials, int numbers) +char *build_grammar(int triplets, int specials, int numbers, int *grammar_size) { if (triplets < 1) { fprintf(stderr, "ERROR: Cannot have less than one triplet."); return NULL; } - int grammar_size = triplets * 3 + specials + numbers; - char *build = malloc(grammar_size + 1); + *grammar_size = triplets * 3 + specials + numbers; + char *build = malloc(*grammar_size + 1); if (build == NULL) { perror("malloc"); return NULL; } - build[grammar_size] = 0; + build[*grammar_size] = 0; memcpy(build, "Cvc", 3); for (int i = 1; i < triplets; ++i) @@ -127,7 +127,7 @@ int main(int argc, char *argv[]) * Take arguments as triplets, specials, numbers * atoi might be scuffed but so be it (it just goes = 0 if invalid input) */ - grammar = build_grammar(atoi(argv[1]), atoi(argv[2]), atoi(argv[3])); + grammar = build_grammar(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), &grammar_size); if (grammar == NULL) { err = true; goto cleanup; -- cgit