rem: buf = malloc(w);
add: buf = malloc(w+1);
context: load_graymap(char *file_name, FILE *file, int w, int h, int max, int raw){    RImage *image;        image = RCreateImage(w, h, 0);    if (!image) {	return NULL;    }    if (!raw) {	    } else {	if (max<256) {	    int x, y;	    char *buf, *ptr;	    	    buf = malloc(w);	    if (!buf) {		return NULL;	    }	    	    ptr = image->data;	    for (y = 0; y < h; y++) {		if (!fgets(buf, w, file)) {		    free(buf);		    goto short_file;		}		for (x = 0; x < w; x++) {		    *(ptr++) = buf[x];		    *(ptr++) = buf[x];		    *(ptr++) = buf[x];		}	    }	    free(buf);	} else {	    	}    }        return image;      short_file:    RErrorCode = RERR_BADIMAGEFILE;    return NULL;}