From dd1d513f1ecc4681737d87a318ec677f07f7c51e Mon Sep 17 00:00:00 2001 From: Masahiko AMANO Date: Thu, 29 Dec 2022 17:22:50 +0300 Subject: [PATCH] fix(core): check if got NULL in all functions --- core/sappyou.c | 8 +++++++- core/sasahyou.c | 8 +++++++- core/shoppyou.c | 6 ++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/core/sappyou.c b/core/sappyou.c index a6c79f7..7ee2db3 100644 --- a/core/sappyou.c +++ b/core/sappyou.c @@ -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; diff --git a/core/sasahyou.c b/core/sasahyou.c index 3a6ace5..93da39b 100644 --- a/core/sasahyou.c +++ b/core/sasahyou.c @@ -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; diff --git a/core/shoppyou.c b/core/shoppyou.c index b2b85f0..6d72da2 100644 --- a/core/shoppyou.c +++ b/core/shoppyou.c @@ -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;