Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added a few checks for null pointers #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 19 additions & 15 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,28 +147,32 @@ static FILE *open_lang_file(const char *language)
}
FILE *fp;
char *filename = malloc(sizeof(char) * (strlen(language) + 7*sizeof(char)));
memset(filename,0,sizeof(char)*strlen(language)+7*sizeof(char));
filename[0] = '.';
memcpy(filename + 1, language, strlen(language));
strncat(filename + strlen(language), ".lang", 5);
if (access(filename, F_OK) != -1) {
fp = fopen(filename, "r");
if (!fp) {
if(!filename) {
return NULL;
} else {
memset(filename,0,sizeof(char)*strlen(language)+7*sizeof(char));
filename[0] = '.';
memcpy(filename + 1, language, strlen(language));
strncat(filename + strlen(language), ".lang", 5);
if (access(filename, F_OK) != -1) {
fp = fopen(filename, "r");
if (!fp) {
#ifdef STATULA_TESTS
return NULL;
return NULL;
#else
eprintf(STATULA_FAIL_IO,"open_lang_file: Failed to open file .%s.lang:", language);
eprintf(STATULA_FAIL_IO,"open_lang_file: Failed to open file .%s.lang:", language);
#endif
}
} else {
}
} else {
#ifdef STATULA_TESTS
return NULL;
return NULL;
#else
eprintf(STATULA_FAIL_IO,"open_lang_file: File \".%s.lang\" was not found:", language);
eprintf(STATULA_FAIL_IO,"open_lang_file: File \".%s.lang\" was not found:", language);
#endif
}
free(filename);
return fp;
}
free(filename);
return fp;
}

void *read_data(const char *source, unsigned long long *num_count, fpn *(*filter)(char *buffer, unsigned long long *num_count, fpn *numbers))
Expand Down
26 changes: 15 additions & 11 deletions src/statula.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,21 @@ int main(int argc, char **argv)

struct settings *settings = parse_cmd_args(argc,argv);

handle_flags(settings);
for (int i = 0; i < settings->in_file_count; i++) {
process_file(settings,i);
if(settings) {
handle_flags(settings);
for (int i = 0; i < settings->in_file_count; i++) {
process_file(settings,i);
}

if ((settings->dataset_flags ^ STATULA_SORT) & STATULA_SORT) {
puts("\nWARNING: Median, mode and skewness could yield incorrect results due to the input not being sorted.\n");
}

free_settings(settings);

return 0;
} else {
return 1;
}

if ((settings->dataset_flags ^ STATULA_SORT) & STATULA_SORT) {
puts("\nWARNING: Median, mode and skewness could yield incorrect results due to the input not being sorted.\n");
}

free_settings(settings);

return 0;
}