sheepy

build system (sheepy) and package manager (spm) for C
git clone https://spartatek.se/git/sheepy.git
Log | Files | Refs | README | LICENSE

commit b2abb3d38c3ad0045901b328d9ebf678c0a84af7
parent 8b08a02241418d492fe83ec1fb8d03158eaa3f7c
Author: Remy Noulin <loader2x@gmail.com>
Date:   Tue,  5 Jan 2021 09:10:39 +0100

add malloc checks in class template

Return an error when it fails

src/sheepy.h | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

Diffstat:
Msrc/sheepy.h | 9+++++++--
1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/sheepy.h b/src/sheepy.h @@ -204,7 +204,10 @@ void initiateClassTemplate(classTemplatet *self) {\n\ \n\ self->type = \"classTemplate\";\n\ if (!classTemplateF) {\n\ - classTemplateF = malloc(sizeof(classTemplateFunctionst));\n\ + isError(classTemplateF, malloc(sizeof(classTemplateFunctionst))) {\n\ + self->f = NULL;\n\ + return;\n\ + }\n\ registerMethodsClassTemplate(classTemplateF);\n\ pErrorNot0(atexit(finalizeClassTemplate));\n\ }\n\ @@ -227,7 +230,7 @@ void registerMethodsClassTemplate(classTemplateFunctionst *f) {\n\ void initiateAllocateClassTemplate(classTemplatet **self) {\n\ \n\ if (self) {\n\ - (*self) = malloc(sizeof(classTemplatet));\n\ + isError(*self, malloc(sizeof(classTemplatet))) return;\n\ if (*self) {\n\ initiateClassTemplate(*self);\n\ }\n\ @@ -245,6 +248,7 @@ classTemplatet* allocClassTemplate(void/* TODO change parameter to get the initi classTemplatet *r = NULL;\n\ \n\ initiateAllocateClassTemplate(&r);\n\ + if (!r) return NULL;\n\ /* TODO copy data given in parameter to the object */\n\ ret r;\n\ }\n\ @@ -283,6 +287,7 @@ local char* toStringClassTemplate(classTemplatet *self) {\n\ local classTemplatet* duplicateClassTemplate(classTemplatet *self) {\n\ \n\ createAllocateClassTemplate(dup);\n\ + if (!dup) return NULL;\n\ /* TODO COPY data */\n\ ret dup;\n\ }\n\