diff --git a/src/interface.c b/src/interface.c index 0184f03be..e2b1d0bd6 100644 --- a/src/interface.c +++ b/src/interface.c @@ -2279,6 +2279,8 @@ void menu_ui(pixel *vid_buf, int i, int *sl, int *sr) { int b=1,bq,mx,my,h,x,y,n=0,height,width,sy,rows=0; pixel *old_vid=(pixel *)calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); + if (!old_vid) + return; fillrect(vid_buf, -1, -1, XRES+1, YRES+MENUSIZE, 0, 0, 0, 192); memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE); @@ -3306,6 +3308,8 @@ int search_ui(pixel *vid_buf) void *thumb, *data; int thlen, dlen; + if (!v_buf) + return 0; memset(v_buf, 0, ((YRES+MENUSIZE)*(XRES+BARSIZE))*PIXELSIZE); memset(img_http, 0, sizeof(img_http)); @@ -4102,6 +4106,8 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date) ui_copytext ctb; pixel *old_vid=(pixel *)calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); + if (!old_vid || !info) + return 0; fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192); viewcountbuffer[0] = 0; @@ -5448,6 +5454,8 @@ char *console_ui(pixel *vid_buf,char error[255],char console_more) { ed.multiline = 0; ed.cursor = 0; //fillrect(vid_buf, -1, -1, XRES, 220, 0, 0, 0, 190); + if (!old_buf) + return NULL; memcpy(old_buf,vid_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); fillrect(old_buf, -1, -1, XRES+BARSIZE, 220, 0, 0, 0, 190); @@ -5663,6 +5671,8 @@ unsigned int decorations_ui(pixel *vid_buf,int *bsx,int *bsy, unsigned int saved box_B.cursor = 0; + if (!old_buf) + return PIXRGB(currR,currG,currB); memcpy(old_buf,vid_buf,(XRES+BARSIZE)*YRES*PIXELSIZE); while (!sdl_poll()) { @@ -6423,6 +6433,8 @@ void catalogue_ui(pixel * vid_buf) ui_edit ed; vid_buf2 = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); + if (!vid_buf2) + return; ed.w = xsize-16-4; ed.x = x0+11; @@ -6811,6 +6823,8 @@ void render_ui(pixel * vid_buf, int xcoord, int ycoord, int orientation) part_vbuf = calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); //Extra video buffer part_vbuf_store = part_vbuf; + if (!o_vid_buf || !part_vbuf || !part_vbuf_store) + return; while (!sdl_poll()) { b = mouse_get_state(&mx, &my); diff --git a/src/main.c b/src/main.c index f1dfa0c35..2a091c206 100644 --- a/src/main.c +++ b/src/main.c @@ -1648,7 +1648,7 @@ int main(int argc, char *argv[]) dump_frame(vid_buf, XRES, YRES, XRES+BARSIZE); if (sdl_key=='v'&&(sdl_mod & (KMOD_LCTRL|KMOD_RCTRL))) { - if (clipboard_ready==1) + if (clipboard_ready==1 && clipboard_data) { load_data = malloc(clipboard_length); memcpy(load_data, clipboard_data, clipboard_length); @@ -2185,17 +2185,21 @@ int main(int argc, char *argv[]) if (copy_mode==1)//CTRL-C, copy { clipboard_data=build_save(&clipboard_length, save_x, save_y, save_w, save_h, bmap, vx, vy, pv, fvx, fvy, signs, parts); - clipboard_ready = 1; + if (clipboard_data) + clipboard_ready = 1; save_mode = 0; copy_mode = 0; } else if (copy_mode==2)//CTRL-X, cut { clipboard_data=build_save(&clipboard_length, save_x, save_y, save_w, save_h, bmap, vx, vy, pv, fvx, fvy, signs, parts); - clipboard_ready = 1; + if (clipboard_data) + { + clipboard_ready = 1; + clear_area(save_x, save_y, save_w, save_h); + } save_mode = 0; copy_mode = 0; - clear_area(save_x, save_y, save_w, save_h); } else//normal save { diff --git a/src/save.c b/src/save.c index 8f4b83b5a..499a8ccc9 100644 --- a/src/save.c +++ b/src/save.c @@ -494,6 +494,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h wallDataLen = blockW*blockH; fanData = malloc((blockW*blockH)*2); fanDataLen = 0; + if (!wallData || !fanData) + { + puts("Save Error, out of memory\n"); + outputData = NULL; + goto fin; + } for(x = blockX; x < blockX+blockW; x++) { for(y = blockY; y < blockY+blockH; y++) @@ -534,6 +540,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h partsPosLastMap = calloc(fullW*fullH, sizeof(unsigned)); partsPosCount = calloc(fullW*fullH, sizeof(unsigned)); partsPosLink = calloc(NPART, sizeof(unsigned)); + if (!partsPosFirstMap || !partsPosLastMap || !partsPosCount || !partsPosLink) + { + puts("Save Error, out of memory\n"); + outputData = NULL; + goto fin; + } for(i = 0; i < NPART; i++) { if(partsptr[i].type) @@ -565,6 +577,12 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h //Store number of particles in each position partsPosData = malloc(fullW*fullH*3); partsPosDataLen = 0; + if (!partsPosData) + { + puts("Save Error, out of memory\n"); + outputData = NULL; + goto fin; + } for (y=0;y