diff options
| author | KatolaZ <katolaz@freaknet.org> | 2019-08-09 09:20:53 +0100 | 
|---|---|---|
| committer | KatolaZ <katolaz@freaknet.org> | 2019-08-09 09:20:53 +0100 | 
| commit | e4c527b0f07b91fb3cd9ba58ba057dfea9da9356 (patch) | |
| tree | 9f6b3ed5ecc616d71d7d188a08eddccac94a75a7 | |
| parent | a6f10d6541be679b0ca328ba85fa44d2935937cd (diff) | |
check all mem allocations
| -rw-r--r-- | draw.c | 12 | ||||
| -rw-r--r-- | lineset.c | 10 | ||||
| -rw-r--r-- | screen.c | 2 | 
3 files changed, 17 insertions, 7 deletions
@@ -221,11 +221,16 @@ void get_arrow(FILE *fc){  	char c;  	int orig_x=x, orig_y=y, arrow_len;  	static short  *arrow = NULL; +	short *tmp = NULL;  	static int arrow_sz;  	if (!arrow){  		arrow_sz = 100;  		arrow = malloc(arrow_sz * sizeof(short)); +		if (arrow == NULL){ +			fprintf(stderr, "Unable to allocate arrow"); +			cleanup(1); +		}  	}  	arrow_len = 0;  	dir = DIR_N; @@ -242,7 +247,12 @@ void get_arrow(FILE *fc){  		/* FIXME: if we are out of bound, do nothing? */  		if (arrow_len == arrow_sz){  			arrow_sz *=2; -			arrow = realloc(arrow, arrow_sz * sizeof(short)); +			tmp = realloc(arrow, arrow_sz * sizeof(short)); +			if (tmp == NULL){ +				fprintf(stderr, "Unable to reallocate arrow"); +				cleanup(1); +			} +			arrow = tmp;  		}  		if (dir != DIR_N){  			arrow[arrow_len++] = dir; @@ -12,9 +12,9 @@ void ensure_line_length(line_t *l, int len){  	if (l->sz < len + 1){  		tmp = realloc(l->s, (len+1) * 2 * sizeof(char)); -		if (!tmp){ +		if (tmp == NULL){  			fprintf(stderr, "Unable to allocate string\n"); -			cleanup(-1); +			cleanup(1);  		}  		l->s = tmp;  		l->sz = (len + 1) * 2; @@ -29,7 +29,7 @@ void alloc_line(line_t *l){  	tmp = malloc((l->sz) * sizeof(char));  	if (tmp == NULL){  		fprintf(stderr, "unable to allocate line\n"); -		cleanup(-1); +		cleanup(1);  	}  	l->s = tmp;  	memset(l->s, BG, l->sz); @@ -46,7 +46,7 @@ void ensure_num_lines(lineset_t *ls, int n){  		tmp = realloc(ls->l, (n + LONG_STEP) * sizeof(line_t));  		if (tmp == NULL){  			fprintf(stderr, "Unable to allocate memory for more lines"); -			cleanup(-1); +			cleanup(1);  		}  		else {  			ls->l = tmp; @@ -147,7 +147,7 @@ void copy_lines_to_ring(int y1, int y2, int which){  		tmp = realloc(undo, (undo_sz + 10) * sizeof(lineset_t));  		if (tmp == NULL){  			fprintf(stderr, "Error allocating undo buffer"); -			cleanup(-1); +			cleanup(1);  		}  		undo = tmp;  		for (i=0; i<10; i++){ @@ -422,7 +422,7 @@ void init_screen(){  	screen.num = HEIGHT;  	if (screen.l == NULL){  		perror("allocating screen"); -		cleanup(-1); +		cleanup(1);  	}  	for (i=0; i<HEIGHT; i++){  		alloc_line(&(screen.l[i]));  | 
