mirror of
https://github.com/lcn2/calc.git
synced 2025-08-19 01:13:27 +03:00
Added missing malloc failure checks
This commit is contained in:
8
hist.c
8
hist.c
@@ -745,10 +745,18 @@ hist_saveline(char *line, int len)
|
|||||||
* Add the line to the end of the history table.
|
* Add the line to the end of the history table.
|
||||||
*/
|
*/
|
||||||
hp = malloc(sizeof(HIST));
|
hp = malloc(sizeof(HIST));
|
||||||
|
if (hp == NULL) {
|
||||||
|
fprintf(stderr, "Out of memory adding line to the history table #0\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
hp->next = NULL;
|
hp->next = NULL;
|
||||||
hp->prev = NULL;
|
hp->prev = NULL;
|
||||||
hp->len = len;
|
hp->len = len;
|
||||||
hp->data = malloc(len);
|
hp->data = malloc(len);
|
||||||
|
if (hp->data == NULL) {
|
||||||
|
fprintf(stderr, "Out of memory adding line to the history table #1\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
memcpy(hp->data, line, len);
|
memcpy(hp->data, line, len);
|
||||||
HS.curhist = ++HS.histcount;
|
HS.curhist = ++HS.histcount;
|
||||||
if (!hist_first)
|
if (!hist_first)
|
||||||
|
8
obj.c
8
obj.c
@@ -571,9 +571,13 @@ defineobject(char *name, int indices[], int count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
oap = (OBJECTACTIONS *) malloc(objectactionsize(count));
|
oap = (OBJECTACTIONS *) malloc(objectactionsize(count));
|
||||||
|
if (oap == NULL) {
|
||||||
|
math_error("Cannot allocate object type #0");
|
||||||
|
/*NOTREACHED*/
|
||||||
|
}
|
||||||
name = addstr(hp, name);
|
name = addstr(hp, name);
|
||||||
if ((oap == NULL) || (name == NULL)) {
|
if (name == NULL) {
|
||||||
math_error("Cannot allocate object type");
|
math_error("Cannot allocate object type #1");
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
oap->oa_count = count;
|
oap->oa_count = count;
|
||||||
|
4
str.c
4
str.c
@@ -59,6 +59,10 @@ initstr(STRINGHEAD *hp)
|
|||||||
{
|
{
|
||||||
if (hp->h_list == NULL) {
|
if (hp->h_list == NULL) {
|
||||||
hp->h_list = (char *)malloc(2000);
|
hp->h_list = (char *)malloc(2000);
|
||||||
|
if (hp->h_list == NULL) {
|
||||||
|
math_error("Cannot allocate string header");
|
||||||
|
/*NOTREACHED*/
|
||||||
|
}
|
||||||
hp->h_avail = 2000;
|
hp->h_avail = 2000;
|
||||||
hp->h_used = 0;
|
hp->h_used = 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user