Add checks for realloc() result

This commit is contained in:
Christian Bauer 2016-01-31 16:00:57 +01:00
parent 07b8b22c9b
commit b58a9260bd

View File

@ -21,6 +21,7 @@
#include "sysdeps.h"
#include <stdlib.h>
#include <assert.h>
#include "mon.h"
#include "mon_cmd.h"
@ -84,11 +85,13 @@ start:
if (mon_token == T_STRING) {
unsigned n = strlen(mon_string);
str = (uint8 *)realloc(str, (len + n - 1 + GRANULARITY) & ~(GRANULARITY - 1));
assert(str != NULL);
memcpy(str + len, mon_string, n);
len += n;
mon_get_token();
} else if (mon_expression(&value)) {
str = (uint8 *)realloc(str, (len + GRANULARITY) & ~(GRANULARITY - 1));
assert(str != NULL);
str[len] = value;
len++;
} else {