diff options
Diffstat (limited to '')
-rw-r--r-- | command/ed.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/command/ed.c b/command/ed.c index 472473f..8e8eae1 100644 --- a/command/ed.c +++ b/command/ed.c @@ -76,7 +76,7 @@ static bool parse_regex(char** end, struct LineAddress* address, enum RegexDirec cap = 8; siz = 0; - buf = malloc(cap * sizeof(long int)); + buf = xalloc(cap * sizeof(long int)); i = (dir == ALL ? 0 : line_current); until = (dir == BEFORE ? 0 : line_count - 1); @@ -88,7 +88,7 @@ static bool parse_regex(char** end, struct LineAddress* address, enum RegexDirec } if (cap == siz) { cap *= 2; - buf = realloc(buf, cap * sizeof(long int)); + buf = xrealloc(buf, cap * sizeof(long int)); } buf[siz] = i; siz++; @@ -112,7 +112,7 @@ static void free_address (struct LineAddress address) { static void expand_buffer(long int** buf, unsigned long* cap, unsigned long* size) { if (*cap == *size) { *cap *= 2; - *buf = realloc(*buf, sizeof(long int) * *cap); + *buf = xrealloc(*buf, sizeof(long int) * *cap); } } @@ -127,7 +127,7 @@ static bool parse_regex_lines(char** end, struct LineAddress* address) { cap = 8; siz = 0; - buf = malloc(cap * sizeof(long int)); + buf = xalloc(cap * sizeof(long int)); addr = *address; if (addr.type == INDEX) { @@ -310,7 +310,7 @@ static void load_empty(void) { free_data(false); line_capacity = 8; - lines = malloc(sizeof(char*) * line_capacity); + lines = xalloc(sizeof(char*) * line_capacity); line_count = 0; line_current = 0; @@ -320,7 +320,7 @@ static void load_empty(void) { static void get_input(FILE* file, char*** buffer, unsigned long* capacity, unsigned long* size) { unsigned long cap = 8; unsigned long siz = 0; - char** buf = malloc(sizeof(char*) * cap); + char** buf = xalloc(sizeof(char*) * cap); char* line = NULL; size_t offset = 0; @@ -329,7 +329,7 @@ static void get_input(FILE* file, char*** buffer, unsigned long* capacity, unsig while (getline(&line, &offset, file) != -1) { if (cap == siz) { cap *= 2; - buf = realloc(buf, sizeof(char*) * cap); + buf = xrealloc(buf, sizeof(char*) * cap); } buf[siz] = line; siz++; @@ -400,7 +400,7 @@ static void expand(unsigned long count) { if (count < line_capacity) return; line_capacity *= 2; if (count > line_capacity) line_capacity = count; - lines = realloc(lines, line_capacity * sizeof(char*)); + lines = xrealloc(lines, line_capacity * sizeof(char*)); } static void append_lines(unsigned long index, char** new, unsigned long new_len) { @@ -495,9 +495,9 @@ static bool get_file_name(char** filename) { len--; } if (default_filename != NULL) { - default_filename = realloc(default_filename, len + 1); + default_filename = xrealloc(default_filename, len + 1); } else { - default_filename = malloc(len + 1); + default_filename = xalloc(len + 1); } memcpy(default_filename, *filename, len + 1); *filename = default_filename; @@ -561,7 +561,7 @@ static void read_file(char* filename) { capacity = 8; size = 0; - buf = malloc(capacity * sizeof(char*)); + buf = xalloc(capacity * sizeof(char*)); get_input(file, &buf, &capacity, &size); if (size < 1) { @@ -584,7 +584,7 @@ static void expand_string(char** buf, int* capacity, int* size, char* text, int if (*size + len >= *capacity) { *capacity *= 2; if (*capacity < *size + len) *capacity = *size + len; - *buf = realloc(*buf, *capacity); + *buf = xrealloc(*buf, *capacity); } memcpy(*buf + *size, text, len); *size += len; @@ -593,7 +593,7 @@ static void expand_string(char** buf, int* capacity, int* size, char* text, int static int substute_string(long int index, long int matches, re_t regex, char* sub, int sub_len) { int capacity = 8; int size = 0; - char* buf = malloc(sizeof(char) * capacity); + char* buf = xalloc(sizeof(char) * capacity); long int left; int offset = 0; |