mirror of
https://github.com/kanjitalk755/macemu.git
synced 2025-01-12 01:30:03 +00:00
Add checks for realloc() result
This commit is contained in:
parent
07b8b22c9b
commit
b58a9260bd
@ -21,6 +21,7 @@
|
|||||||
#include "sysdeps.h"
|
#include "sysdeps.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#include "mon.h"
|
#include "mon.h"
|
||||||
#include "mon_cmd.h"
|
#include "mon_cmd.h"
|
||||||
@ -84,11 +85,13 @@ start:
|
|||||||
if (mon_token == T_STRING) {
|
if (mon_token == T_STRING) {
|
||||||
unsigned n = strlen(mon_string);
|
unsigned n = strlen(mon_string);
|
||||||
str = (uint8 *)realloc(str, (len + n - 1 + GRANULARITY) & ~(GRANULARITY - 1));
|
str = (uint8 *)realloc(str, (len + n - 1 + GRANULARITY) & ~(GRANULARITY - 1));
|
||||||
|
assert(str != NULL);
|
||||||
memcpy(str + len, mon_string, n);
|
memcpy(str + len, mon_string, n);
|
||||||
len += n;
|
len += n;
|
||||||
mon_get_token();
|
mon_get_token();
|
||||||
} else if (mon_expression(&value)) {
|
} else if (mon_expression(&value)) {
|
||||||
str = (uint8 *)realloc(str, (len + GRANULARITY) & ~(GRANULARITY - 1));
|
str = (uint8 *)realloc(str, (len + GRANULARITY) & ~(GRANULARITY - 1));
|
||||||
|
assert(str != NULL);
|
||||||
str[len] = value;
|
str[len] = value;
|
||||||
len++;
|
len++;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user