fix(core): check if got NULL in all functions

This commit is contained in:
Masahiko AMANO 2022-12-29 17:22:50 +03:00
parent 6a927f4644
commit dd1d513f1e
3 changed files with 20 additions and 2 deletions

View File

@ -99,6 +99,9 @@ int sappyou_save(Sappyou *sappyou) {
}
int sappyou_open(Sappyou *sappyou, const char *path) {
if (path == NULL) {
return 1;
}
sappyou->file = fopen(path, "rb");
if (sappyou->file == NULL) {
return 1;
@ -107,6 +110,9 @@ int sappyou_open(Sappyou *sappyou, const char *path) {
}
int sappyou_dump(Sappyou *sappyou, const char *path) {
if (path == NULL) {
return 1;
}
sappyou->file = fopen(path, "wb");
if (sappyou->file == NULL) {
return 1;
@ -115,7 +121,7 @@ int sappyou_dump(Sappyou *sappyou, const char *path) {
}
int tanzaku_add(Sappyou *sappyou, const char *name, const char *description) {
if (sappyou->size == -1 && sappyou->hole_cnt == 0) {
if (name == NULL || description == NULL || sappyou->size == -1 && sappyou->hole_cnt == 0) {
return 1;
}
Tanzaku newbie;

View File

@ -98,6 +98,9 @@ int sasahyou_save(Sasahyou *sasahyou) {
}
int sasahyou_open(Sasahyou *sasahyou, const char *path) {
if (path == NULL) {
return 1;
}
sasahyou->file = fopen(path, "rb");
if (sasahyou->file == NULL) {
return 1;
@ -106,6 +109,9 @@ int sasahyou_open(Sasahyou *sasahyou, const char *path) {
}
int sasahyou_dump(Sasahyou *sasahyou, const char *path) {
if (path == NULL) {
return 1;
}
sasahyou->file = fopen(path, "wb");
if (sasahyou->file == NULL) {
return 1;
@ -114,7 +120,7 @@ int sasahyou_dump(Sasahyou *sasahyou, const char *path) {
}
int sasa_add(Sasahyou *sasahyou, const char *path) {
if (sasahyou->size == -1 && sasahyou->hole_cnt == 0) {
if (path == NULL || sasahyou->size == -1 && sasahyou->hole_cnt == 0) {
return 1;
}
Sasa newbie;

View File

@ -81,6 +81,9 @@ int shoppyou_save(Shoppyou *shoppyou) {
}
int shoppyou_open(Shoppyou *shoppyou, const char *path) {
if (path == NULL) {
return 1;
}
shoppyou->file = fopen(path, "rb");
if (shoppyou->file == NULL) {
return 1;
@ -90,6 +93,9 @@ int shoppyou_open(Shoppyou *shoppyou, const char *path) {
}
int shoppyou_dump(Shoppyou *shoppyou, const char *path) {
if (path == NULL) {
return 1;
}
shoppyou->file = fopen(path, "wb");
if (shoppyou->file == NULL) {
return 1;