Fixed unintended behaviour

This commit is contained in:
Alessandro Ferro 2023-05-20 12:31:48 +02:00
parent 4188059e4e
commit 183982a8cc
2 changed files with 7 additions and 13 deletions

3
build.sh Normal file → Executable file
View File

@ -1,2 +1 @@
#! /bin/bash gcc -o3 dircomp.c -lssl -lcrypto -o dircomp
gcc -o3 dircomp.c -lssl -lcrypto -o dircomp

View File

@ -13,11 +13,6 @@
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct arguments arguments = get_arguments(argc, 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_analyze1 = malloc(strlen(arguments.directory1) * sizeof(char) + 1);
char* directory_to_analyze2 = malloc(strlen(arguments.directory2) * sizeof(char) + 1); char* directory_to_analyze2 = malloc(strlen(arguments.directory2) * sizeof(char) + 1);
@ -25,8 +20,6 @@ int main(int argc, char *argv[])
strcpy(directory_to_analyze2, arguments.directory2); strcpy(directory_to_analyze2, arguments.directory2);
free(arguments.directory1); free(arguments.directory1);
free(arguments.directory2); free(arguments.directory2);
arguments.directory1 = NULL;
arguments.directory2 = NULL;
if (analyze_directories(directory_to_analyze1, directory_to_analyze2, &arguments)) if (analyze_directories(directory_to_analyze1, directory_to_analyze2, &arguments))
{ {
@ -44,10 +37,7 @@ int main(int argc, char *argv[])
struct arguments get_arguments(int argc, char **argv) struct arguments get_arguments(int argc, char **argv)
{ {
struct arguments provided_arguments = {"", "", false, false, false, false, false}; struct arguments provided_arguments = {"", "", false, false, false, false, false};
if(argc == 1){
provided_arguments.h = true;
return provided_arguments;
}
char option; char option;
while ((option = getopt(argc, argv, "rvhfd")) != -1) while ((option = getopt(argc, argv, "rvhfd")) != -1)
{ {
@ -71,6 +61,11 @@ struct arguments get_arguments(int argc, char **argv)
} }
} }
if(provided_arguments.h || argc == 1){
print_help();
exit(0);
}
// Get directories // Get directories
if ((argc - optind) < 2) if ((argc - optind) < 2)
{ {