Skip to content

Commit

Permalink
Fixed unintended behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
xfarrow committed May 20, 2023
1 parent 4188059 commit 183982a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
3 changes: 1 addition & 2 deletions build.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
#! /bin/bash
gcc -o3 dircomp.c -lssl -lcrypto -o dircomp
gcc -o3 dircomp.c -lssl -lcrypto -o dircomp
17 changes: 6 additions & 11 deletions dircomp.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,13 @@
int main(int argc, char *argv[])
{
struct arguments arguments = get_arguments(argc, argv);
if (arguments.h == true)
{
print_help();
return 0;
}

char* directory_to_analyze1 = malloc(strlen(arguments.directory1) * sizeof(char) + 1);
char* directory_to_analyze2 = malloc(strlen(arguments.directory2) * sizeof(char) + 1);
strcpy(directory_to_analyze1, arguments.directory1);
strcpy(directory_to_analyze2, arguments.directory2);
free(arguments.directory1);
free(arguments.directory2);
arguments.directory1 = NULL;
arguments.directory2 = NULL;

if (analyze_directories(directory_to_analyze1, directory_to_analyze2, &arguments))
{
Expand All @@ -44,10 +37,7 @@ int main(int argc, char *argv[])
struct arguments get_arguments(int argc, char **argv)
{
struct arguments provided_arguments = {"", "", false, false, false, false, false};
if(argc == 1){
provided_arguments.h = true;
return provided_arguments;
}

char option;
while ((option = getopt(argc, argv, "rvhfd")) != -1)
{
Expand All @@ -71,6 +61,11 @@ struct arguments get_arguments(int argc, char **argv)
}
}

if(provided_arguments.h || argc == 1){
print_help();
exit(0);
}

// Get directories
if ((argc - optind) < 2)
{
Expand Down

0 comments on commit 183982a

Please sign in to comment.