cppcheck nullPointerOutOfMemory

This commit is contained in:
Philippe Teuwen 2025-03-24 23:46:43 +01:00
commit ad84875afd
44 changed files with 314 additions and 5 deletions

View file

@ -469,6 +469,12 @@ int main(int argc, char **argv) {
uint8_t num_output_files = argc - 3;
FILE **outfiles = calloc(num_output_files, sizeof(FILE *));
char **outfile_names = calloc(num_output_files, sizeof(char *));
if (outfiles == NULL || outfile_names == NULL) {
fprintf(stderr, "Error. Cannot allocate memory for output files\n\n");
free(outfiles);
free(outfile_names);
return (EXIT_FAILURE);
}
for (uint8_t i = 0; i < num_output_files; i++) {
outfile_names[i] = argv[i + 3];
outfiles[i] = fopen(outfile_names[i], "wb");
@ -526,6 +532,12 @@ int main(int argc, char **argv) {
FILE **infiles = calloc(num_input_files, sizeof(FILE *));
char **infile_names = calloc(num_input_files, sizeof(char *));
if (infiles == NULL || infile_names == NULL) {
fprintf(stderr, "Error. Cannot allocate memory for input files\n\n");
free(infile_names);
free(infiles);
return (EXIT_FAILURE);
}
for (uint8_t i = 0; i < num_input_files; i++) {
infile_names[i] = argv[i + (generate_version_file ? 2 : 1)];
infiles[i] = fopen(infile_names[i], "rb");

View file

@ -737,6 +737,10 @@ int main(int argc, const char *argv[]) {
printf("----------- " _CYAN_("Phase 1 pre-processing") " ------------------------\n");
printf("Testing default keys using NESTED authentication...\n");
struct thread_key_args *def = calloc(1, sizeof(struct thread_key_args));
if (def == NULL) {
fprintf(stderr, "Memory allocation failed\n");
exit(EXIT_FAILURE);
}
def->thread = 0;
def->idx = 0;
def->uid = uid;
@ -758,6 +762,10 @@ int main(int argc, const char *argv[]) {
// the rest of available threads to EV1 scenario
for (int i = 0; i < thread_count; ++i) {
struct thread_args *a = calloc(1, sizeof(struct thread_args));
if (a == NULL) {
fprintf(stderr, "Memory allocation failed\n");
exit(EXIT_FAILURE);
}
a->xored = xored;
a->thread = i;
a->idx = i;
@ -780,6 +788,10 @@ int main(int argc, const char *argv[]) {
// the rest of available threads to EV1 scenario
for (int i = 0; i < thread_count; ++i) {
struct thread_args *a = calloc(1, sizeof(struct thread_args));
if (a == NULL) {
fprintf(stderr, "Memory allocation failed\n");
exit(EXIT_FAILURE);
}
a->xored = xored;
a->thread = i;
a->idx = i;
@ -823,6 +835,10 @@ int main(int argc, const char *argv[]) {
// threads
for (int i = 0; i < thread_count; ++i) {
struct thread_key_args *b = calloc(1, sizeof(struct thread_key_args));
if (b == NULL) {
fprintf(stderr, "Memory allocation failed\n");
exit(EXIT_FAILURE);
}
b->thread = i;
b->idx = i;
b->uid = uid;

View file

@ -290,6 +290,10 @@ int main(int argc, const char *argv[]) {
// threads
for (int i = 0; i < thread_count; ++i) {
struct thread_args *a = calloc(1, sizeof(struct thread_args));
if (a == NULL) {
fprintf(stderr, "Failed to allocate memory for thread arguments\n");
exit(EXIT_FAILURE);
}
a->thread = i;
a->idx = i;
a->uid = uid;

View file

@ -277,6 +277,10 @@ int main(int argc, char *argv[]) {
uint64_t stop_time = time(NULL);
for (int i = 0; i < thread_count; ++i) {
struct thread_args *a = calloc(1, sizeof(struct thread_args));
if (a == NULL) {
fprintf(stderr, "Failed to allocate memory for thread arguments\n");
exit(EXIT_FAILURE);
}
a->thread = i;
a->idx = i;
a->starttime = start_time;

View file

@ -471,6 +471,10 @@ int main(int argc, char *argv[]) {
uint64_t stop_time = time(NULL);
for (int i = 0; i < thread_count; ++i) {
struct thread_args *a = calloc(1, sizeof(struct thread_args));
if (a == NULL) {
fprintf(stderr, "Failed to allocate memory for thread arguments\n");
exit(EXIT_FAILURE);
}
a->thread = i;
a->idx = i;
a->generator_idx = g_idx;