Browse Source

removed NULL checks, since free(NULL) is ignored

master
Robby Zambito 2 months ago
parent
commit
b6250d6512
2 changed files with 16 additions and 46 deletions
  1. +8
    -23
      day4/1/c/main.c
  2. +8
    -23
      day4/2/c/main.c

+ 8
- 23
day4/1/c/main.c View File

@ -67,29 +67,14 @@ int main(int argc, char **argv) {
}
void resetPassport(struct Passport *p) {
if (p->byr != NULL)
free(p->byr);
if (p->iyr != NULL)
free(p->iyr);
if (p->eyr != NULL)
free(p->eyr);
if (p-> hgt != NULL)
free(p->hgt);
if (p-> hcl != NULL)
free(p->hcl);
if (p->ecl != NULL)
free(p->ecl);
if (p->pid != NULL)
free(p->pid);
if (p->cid != NULL)
free(p->cid);
free(p->byr);
free(p->iyr);
free(p->eyr);
free(p->hgt);
free(p->hcl);
free(p->ecl);
free(p->pid);
free(p->cid);
/* Set all fields back to NULL pointers */
memset(p, 0, sizeof(struct Passport));

+ 8
- 23
day4/2/c/main.c View File

@ -69,29 +69,14 @@ int main(int argc, char **argv) {
}
void resetPassport(struct Passport *p) {
if (p->byr != NULL)
free(p->byr);
if (p->iyr != NULL)
free(p->iyr);
if (p->eyr != NULL)
free(p->eyr);
if (p-> hgt != NULL)
free(p->hgt);
if (p-> hcl != NULL)
free(p->hcl);
if (p->ecl != NULL)
free(p->ecl);
if (p->pid != NULL)
free(p->pid);
if (p->cid != NULL)
free(p->cid);
free(p->byr);
free(p->iyr);
free(p->eyr);
free(p->hgt);
free(p->hcl);
free(p->ecl);
free(p->pid);
free(p->cid);
/* Set all fields back to NULL pointers */
memset(p, 0, sizeof(struct Passport));

Loading…
Cancel
Save