[Scummvm-git-logs] scummvm master -> f825f186af394325577760a7b160b7b128264d90

Strangerke noreply at scummvm.org
Wed Feb 4 15:52:12 UTC 2026


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://api.github.com/repos/scummvm/scummvm .

Summary:
5c8fe1275e M4: BURGER: Fix some PVS Studio V1037 in section6 (identical switch cases) after a check in assembly
f825f186af M4: Add an error check in mem_alloc and remove the checks used after every calls


Commit: 5c8fe1275ea3b13f48a32fa3f460726fe0ba8765
    https://github.com/scummvm/scummvm/commit/5c8fe1275ea3b13f48a32fa3f460726fe0ba8765
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2026-02-04T16:51:55+01:00

Commit Message:
M4: BURGER: Fix some PVS Studio V1037 in section6 (identical switch cases) after a check in assembly

Changed paths:
    engines/m4/burger/rooms/section6/section6.cpp


diff --git a/engines/m4/burger/rooms/section6/section6.cpp b/engines/m4/burger/rooms/section6/section6.cpp
index 4dd69b3541e..e89bda6049d 100644
--- a/engines/m4/burger/rooms/section6/section6.cpp
+++ b/engines/m4/burger/rooms/section6/section6.cpp
@@ -465,14 +465,12 @@ void Section6::freeDigi(int state) {
 		digi_unload("600_007");
 		break;
 	case 6010:
+	case 6012:
 		digi_unload("600xxxxx");
 		break;
 	case 6011:
 		digi_unload("600_010");
 		break;
-	case 6012:
-		digi_unload("600xxxxx");
-		break;
 	default:
 		break;
 	}


Commit: f825f186af394325577760a7b160b7b128264d90
    https://github.com/scummvm/scummvm/commit/f825f186af394325577760a7b160b7b128264d90
Author: Strangerke (arnaud.boutonne at gmail.com)
Date: 2026-02-04T16:51:55+01:00

Commit Message:
M4: Add an error check in mem_alloc and remove the checks used after every calls

Changed paths:
    engines/m4/adv_r/adv_been.cpp
    engines/m4/adv_r/adv_hotspot.cpp
    engines/m4/adv_r/adv_rails.cpp
    engines/m4/adv_r/conv_io.cpp
    engines/m4/burger/gui/gui_gizmo.cpp
    engines/m4/fileio/fstream.cpp
    engines/m4/fileio/sys_file.cpp
    engines/m4/graphics/gr_buff.cpp
    engines/m4/graphics/gr_font.cpp
    engines/m4/graphics/gr_sprite.cpp
    engines/m4/gui/game_menu.cpp
    engines/m4/gui/gui_cheapo.cpp
    engines/m4/gui/gui_dialog.cpp
    engines/m4/gui/gui_item.cpp
    engines/m4/gui/gui_menu_items.cpp
    engines/m4/gui/gui_mouse.cpp
    engines/m4/gui/gui_sys.cpp
    engines/m4/gui/gui_vmng_screen.cpp
    engines/m4/mem/mem.cpp
    engines/m4/mem/memman.h
    engines/m4/platform/tile/tile_read.cpp
    engines/m4/wscript/ws_cruncher.cpp
    engines/m4/wscript/ws_hal.cpp
    engines/m4/wscript/ws_hal.h
    engines/m4/wscript/ws_load.cpp
    engines/m4/wscript/ws_machine.cpp


diff --git a/engines/m4/adv_r/adv_been.cpp b/engines/m4/adv_r/adv_been.cpp
index c7b71f1d916..7a400133bfb 100644
--- a/engines/m4/adv_r/adv_been.cpp
+++ b/engines/m4/adv_r/adv_been.cpp
@@ -31,10 +31,6 @@ namespace M4 {
 bool player_been_init(int16 num_scenes) {
 	assert(num_scenes == TOTAL_SCENES);
 	_G(scene_list).table = (int16 *)mem_alloc(sizeof(int16) * num_scenes, "been_scenes");
-
-	if (!_G(scene_list).table)
-		error_show(FL, 'OOM!', "player_been_init");
-
 	_G(scene_list).total_scenes = num_scenes;
 	player_reset_been();
 
diff --git a/engines/m4/adv_r/adv_hotspot.cpp b/engines/m4/adv_r/adv_hotspot.cpp
index c68e8ccfc88..bb3c69b026e 100644
--- a/engines/m4/adv_r/adv_hotspot.cpp
+++ b/engines/m4/adv_r/adv_hotspot.cpp
@@ -89,8 +89,6 @@ void hotspot_newPrep(HotSpotRec *h, const char *prep) {
 
 HotSpotRec *hotspot_new(int x1, int y1, int x2, int y2) {
 	HotSpotRec *newSpot = (HotSpotRec *)mem_alloc(sizeof(HotSpotRec), STR_HOT_SPOT);
-	if (!newSpot)
-		return newSpot;
 
 	newSpot->ul_x = x1;
 	newSpot->ul_y = y1;
@@ -112,8 +110,6 @@ HotSpotRec *hotspot_new(int x1, int y1, int x2, int y2) {
 
 HotSpotRec *hotspot_duplicate(HotSpotRec *dupMe) {
 	HotSpotRec *newSpot = (HotSpotRec *)mem_alloc(sizeof(HotSpotRec), STR_HOT_SPOT);
-	if (!newSpot)
-		return newSpot;
 
 	newSpot->ul_x = dupMe->ul_x;
 	newSpot->ul_y = dupMe->ul_y;
diff --git a/engines/m4/adv_r/adv_rails.cpp b/engines/m4/adv_r/adv_rails.cpp
index c5a1123d2cb..a8ba4732119 100644
--- a/engines/m4/adv_r/adv_rails.cpp
+++ b/engines/m4/adv_r/adv_rails.cpp
@@ -41,14 +41,10 @@ bool InitRails() {
 	}
 
 	// Create the stack. Since any path through a series of nodes can have at most MAXRAILNODES...
-	if ((_G(rails).stackBottom = (railNode **)mem_alloc(sizeof(railNode *) * MAXRAILNODES, STR_RAILNODE)) == nullptr) {
-		return false;
-	}
+	_G(rails).stackBottom = (railNode **)mem_alloc(sizeof(railNode *) * MAXRAILNODES, STR_RAILNODE);
 
 	// Allocate the array of railNode pointers and initialize...
-	if ((_G(rails).myNodes = (railNode **)mem_alloc(sizeof(railNode *) * MAXRAILNODES, STR_RAILNODE)) == nullptr) {
-		return false;
-	}
+	_G(rails).myNodes = (railNode **)mem_alloc(sizeof(railNode *) * MAXRAILNODES, STR_RAILNODE);
 
 	for (i = 0; i < MAXRAILNODES; i++) {
 		_G(rails).myNodes[i] = nullptr;
@@ -57,13 +53,7 @@ bool InitRails() {
 	// Calculate the size of the edge table, allocate, and initialize
 	// The edge table stores the upper triangle of a square matrix.
 	const int32 edgeTableSize = (MAXRAILNODES * (MAXRAILNODES - 1)) >> 1;
-	if ((_G(rails).myEdges = (int16 *)mem_alloc(sizeof(int16) * edgeTableSize, "edge table")) == nullptr) {
-		return false;
-	}
-
-	for (i = 0; i < edgeTableSize; i++) {
-		_G(rails).myEdges[i] = 0;
-	}
+	_G(rails).myEdges = (int16 *)mem_alloc(sizeof(int16) * edgeTableSize, "edge table");
 
 	// Set the parameters and return
 	_G(rails).noWalkRectList = nullptr;
@@ -121,18 +111,13 @@ void ClearRails(void) {
 
 
 noWalkRect *intr_add_no_walk_rect(int32 x1, int32 y1, int32 x2, int32 y2, int32 altX, int32 altY, Buffer *walkCodes) {
-	noWalkRect *newRect;
-
 	// Parameter verification
 	if ((x2 < x1) || (y2 < y1)) {
 		return nullptr;
 	}
 
 	// Create new noWalkRect structure
-	if ((newRect = (noWalkRect *)mem_alloc(sizeof(noWalkRect), "intr noWalkRect")) == nullptr) {
-		error_show(FL, 'IADN', "rect size: %d %d %d %d", x1, y1, x2, y2);
-		return nullptr;
-	}
+	noWalkRect *newRect = (noWalkRect *)mem_alloc(sizeof(noWalkRect), "intr noWalkRect");
 
 	// Initialize the new rect
 	newRect->x1 = x1;
@@ -603,9 +588,7 @@ int32 AddRailNode(int32 x, int32 y, Buffer *walkCodes, bool restoreEdges) {
 
 	if (i < MAXRAILNODES) {
 		railNode *newNode = (railNode *)mem_alloc(sizeof(railNode), "railNode");
-		if (newNode == nullptr) {
-			return -1;
-		}
+
 		newNode->nodeID = (Byte)i;
 		newNode->x = (int16)x;
 		newNode->y = (int16)y;
@@ -691,8 +674,6 @@ void DisposePath(railNode *pathStart) {
 }
 
 static railNode *DuplicatePath(railNode *pathStart) {
-	railNode *newNode;
-
 	// Initialize pointers
 	railNode *firstNode = nullptr;
 	railNode *prevNode = nullptr;
@@ -704,10 +685,8 @@ static railNode *DuplicatePath(railNode *pathStart) {
 	while (pathNode) {
 
 		// Create a new railNode, and duplicate values
-		if ((newNode = (railNode *)mem_alloc(sizeof(railNode), "+RAIL")) == nullptr) {
-			error_show(FL, 'OOM!', "Could not alloc railNode");
-			return nullptr;
-		}
+		railNode *newNode = (railNode *)mem_alloc(sizeof(railNode), "+RAIL");
+
 		newNode->x = pathNode->x;
 		newNode->y = pathNode->y;
 		newNode->shortPath = nullptr;
@@ -750,10 +729,6 @@ railNode *CreateCustomPath(int coord, ...) {
 
 		// Create a new node struct
 		railNode *newNode = (railNode *)mem_alloc(sizeof(railNode), "railNode");
-		if (newNode == nullptr) {
-			error_show(FL, 'OOM!', "could not alloc railNode");
-			return nullptr;
-		}
 
 		// Set the new node values...
 		newNode->x = x;
diff --git a/engines/m4/adv_r/conv_io.cpp b/engines/m4/adv_r/conv_io.cpp
index 319f08ee218..90da5b6f7bf 100644
--- a/engines/m4/adv_r/conv_io.cpp
+++ b/engines/m4/adv_r/conv_io.cpp
@@ -373,8 +373,6 @@ static void conv_save_state(Conv *c) {
 		file_size = _GC(convSave).size();
 
 		conv_save_buff = (char *)mem_alloc(file_size, "conv save buff");
-		if (!conv_save_buff)
-			error_show(FL, 'OOM!');
 
 		Common::copy(&_GC(convSave)[0], &_GC(convSave)[0] + file_size, &conv_save_buff[0]);
 
@@ -396,8 +394,6 @@ static void conv_save_state(Conv *c) {
 
 			mem_free(conv_save_buff);
 			conv_save_buff = (char *)mem_alloc(amt_to_write + NAME_SIZE + sizeof(int32), "conv save buff");
-			if (!conv_save_buff)
-				error_show(FL, 'OOM!');
 
 			memcpy(&conv_save_buff[offset], fname, NAME_SIZE * sizeof(char));
 			offset += NAME_SIZE * sizeof(char);
@@ -411,8 +407,6 @@ static void conv_save_state(Conv *c) {
 		offset = 0;
 
 		conv_save_buff = (char *)mem_alloc(amt_to_write + NAME_SIZE + sizeof(int32), "conv save buff");
-		if (!conv_save_buff)
-			error_show(FL, 'OOM!');
 
 		memcpy(&conv_save_buff[offset], fname, NAME_SIZE * sizeof(char));
 		offset += NAME_SIZE * sizeof(char);
@@ -543,8 +537,6 @@ static Conv *conv_restore_state(Conv *c) {
 	}
 
 	char *conv_save_buff = (char *)mem_alloc(file_size, "conv save buff");
-	if (!conv_save_buff)
-		error_show(FL, 'OOM!');
 
 	// ------------------
 
diff --git a/engines/m4/burger/gui/gui_gizmo.cpp b/engines/m4/burger/gui/gui_gizmo.cpp
index f00fb7d698e..db7606709f4 100644
--- a/engines/m4/burger/gui/gui_gizmo.cpp
+++ b/engines/m4/burger/gui/gui_gizmo.cpp
@@ -379,13 +379,9 @@ static bool gizmo_load_sprites(const char *name, size_t count) {
 			&_GIZMO(palOffset), _GIZMO(palette)) > 0) {
 		gr_pal_set_range(_GIZMO(palette), 64, 192);
 		_GIZMO(assetName) = mem_strdup(name);
-
 		_GIZMO(spriteCount) = count;
 		_GIZMO(sprites) = (M4sprite **)mem_alloc(count * sizeof(M4sprite *), "*sprites array");
 
-		if (!_GIZMO(sprites))
-			error("gizmo_load_sprites - Unable to allocate GIZMO %ld sprites", count);
-
 		for (size_t idx = 0; idx < count; ++idx) {
 			_GIZMO(sprites)[idx] = CreateSprite(_GIZMO(seriesHandle), _GIZMO(celsOffset),
 				idx, nullptr, nullptr);
@@ -800,8 +796,6 @@ static GizmoItem *gizmo_add_item(Gizmo *gizmo, int id,
 
 	// Create new item
 	GizmoItem *item = (GizmoItem *)mem_alloc(sizeof(GizmoItem), "*gui gizmo item");
-	if (!item)
-		error("gizmo_add_item - Not enough emory to create item (%zu bytes)", sizeof(GizmoItem));
 
 	// Put the new item at the head of the list
 	item->_next = gizmo->_items;
@@ -827,9 +821,6 @@ static GizmoItem *gizmo_add_item(Gizmo *gizmo, int id,
 	}
 
 	GizmoButton *btn = (GizmoButton *)mem_alloc(sizeof(GizmoButton), "*gizmo button");
-	if (!btn)
-		error("gizmo_add_item - Not enough emory to create btn (%zu bytes)", sizeof(GizmoButton));
-
 	btn->_state = selected ? SELECTED : NOTHING;
 	btn->_index = btnIndex;
 	btn->_field8 = arg9;
@@ -857,8 +848,6 @@ static Gizmo *gui_create_gizmo(M4sprite *sprite, int sx, int sy, uint scrnFlags)
 		return nullptr;
 
 	Gizmo *gui = (Gizmo *)mem_alloc(sizeof(Gizmo), "*gui gizmo");
-	if (!gui)
-		return nullptr;
 
 	GrBuff *grBuff = new GrBuff(sprite->w, sprite->h);
 	gui->_grBuff = grBuff;
diff --git a/engines/m4/fileio/fstream.cpp b/engines/m4/fileio/fstream.cpp
index 1173cf8b861..2cf310e2ca7 100644
--- a/engines/m4/fileio/fstream.cpp
+++ b/engines/m4/fileio/fstream.cpp
@@ -81,9 +81,6 @@ strmRequest *f_stream_Open(SysFile *srcFile, int32 fileOffset, int32 strmMinBuff
 
 	// Allocate a new stream request struct
 	strmRequest *newStream = (strmRequest *)mem_alloc(sizeof(strmRequest), STR_STRMREQ);
-	if (newStream == nullptr) {
-		error_show(FL, 'OOM!', "%d", sizeof(strmRequest));
-	}
 
 	// Get memory. If there's not enough memory, a exception will be triggered in NewHandle
 	newStream->strmHandle = NewHandle(strmBuffSize, "stream buff");
@@ -191,9 +188,7 @@ static bool UnwrapStream(strmRequest *myStream) {
 
 		// Calculate how many bytes to store and copy to a temporary buffer
 		bytesToMove = (byte *)myStream->strmHead - (byte *)myStream->strmBuff;
-
-		if ((tempBuff = (uint8 *)mem_alloc(bytesToMove, "stream temp buff")) == nullptr)
-			error_show(FL, 'OOM!', "UnwrapStream() failed - temp buff avail: %d", bytesToMove);
+		tempBuff = (uint8 *)mem_alloc(bytesToMove, "stream temp buff");
 
 		memcpy(tempBuff, myStream->strmBuff, bytesToMove);
 	}
diff --git a/engines/m4/fileio/sys_file.cpp b/engines/m4/fileio/sys_file.cpp
index 77f1b3e0ad2..7668bbecc0c 100644
--- a/engines/m4/fileio/sys_file.cpp
+++ b/engines/m4/fileio/sys_file.cpp
@@ -113,7 +113,6 @@ void SysFile::open_read_low_level() {
 				const byte hagfile = temp_fp.readByte();
 
 				Hag_Name_Record *temp_ptr = (Hag_Name_Record *)mem_alloc(sizeof(Hag_Name_Record), "hag_name_list");
-				assert(temp_ptr);
 
 				// Check hag file exists or not
 				Common::Path local_name(f_extension_new(hag_name, "HAG"));
@@ -301,12 +300,6 @@ bool SysFile::open_hash_file() {
 
 				// Add this new open hag file in resource dir into open hag file list
 				temp_ptr = (Hag_Record *)mem_alloc(sizeof(Hag_Record), "Hag_File_List");
-				if (!temp_ptr) {
-					f_io_close(temp_fp);
-					error("creating Hag_record");
-					hag_success = 0;
-					return 0;
-				}
 
 				Common::strcpy_s(temp_ptr->hag_name, temp_name.c_str());
 				temp_ptr->hag_fp = temp_fp;
@@ -329,12 +322,6 @@ bool SysFile::open_hash_file() {
 			else {
 				// add this new open hag file in exec dir into its list
 				temp_ptr = (Hag_Record *)mem_alloc(sizeof(Hag_Record), "Hag_File_List");
-				if (!temp_ptr) {
-					f_io_close(temp_fp);
-					error("creating hag_record");
-					hag_success = 0;
-					return 0;
-				}
 
 				Common::strcpy_s(temp_ptr->hag_name, hag_name.c_str());
 				temp_ptr->hag_fp = temp_fp;
diff --git a/engines/m4/graphics/gr_buff.cpp b/engines/m4/graphics/gr_buff.cpp
index a0c2e306dc4..cec52140a6f 100644
--- a/engines/m4/graphics/gr_buff.cpp
+++ b/engines/m4/graphics/gr_buff.cpp
@@ -134,12 +134,7 @@ int32 gr_buffer_init(Buffer *buf, const char *name, int32 w, int32 h) {
 	buf->w = w;
 	buf->h = h;
 	buf->stride = w;
-
 	buf->data = (uint8 *)mem_alloc(buf->stride * h, name);
-	if (buf->data == nullptr)
-		error_show(FL, 'OOM!', "buffer: %s - w:%d h:%d bytes:%d", name, buf->stride, h, buf->stride * h);
-
-	memset(buf->data, 0, buf->stride * h);
 
 	return (true);
 }
diff --git a/engines/m4/graphics/gr_font.cpp b/engines/m4/graphics/gr_font.cpp
index 94d798720e0..037411539b1 100644
--- a/engines/m4/graphics/gr_font.cpp
+++ b/engines/m4/graphics/gr_font.cpp
@@ -182,8 +182,6 @@ void gr_font_set_color(uint8 foreground) {
 
 Font *gr_font_create_system_font() {
 	_G(interfaceFont) = (Font *)mem_alloc(sizeof(Font), "Font");
-	if (!_G(interfaceFont))
-		error("font struct");
 
 	_G(interfaceFont)->max_y_size = font_intr_h;
 	_G(interfaceFont)->max_x_size = font_intr_w;
@@ -364,8 +362,6 @@ Font *gr_font_load(const char *fontName) {
 		error_show(FL, 'FNTL', "font: %s chkpnt: %d", (const char *)fontName, 0);
 
 	Font *newFont = (Font *)mem_alloc(sizeof(Font), STR_FONTSTRUCT);
-	if (!newFont)
-		error_show(FL, 'OOM!', "_G(font) struct");
 
 	newFont->max_y_size = fontFile.readByte();
 	newFont->max_x_size = fontFile.readByte();
@@ -378,8 +374,6 @@ Font *gr_font_load(const char *fontName) {
 
 	// width table
 	newFont->width = (byte *)mem_alloc(256, STR_FONTWIDTH);
-	if (!newFont->width)
-		error_show(FL, 'OOM!', "_G(font) width table");
 
 	fontFile.read(newFont->width, 256);
 
@@ -390,8 +384,6 @@ Font *gr_font_load(const char *fontName) {
 
 	// offset table
 	newFont->offset = (short *)mem_alloc(256 * sizeof(int16), STR_FONTOFF);
-	if (!newFont->offset)
-		error_show(FL, 'OOM!', "font offset table");
 
 	for (int i = 0; i < 256; i++)
 		newFont->offset[i] = fontFile.readSint16LE();
@@ -403,8 +395,6 @@ Font *gr_font_load(const char *fontName) {
 
 	// pixData
 	newFont->pixData = (byte *)mem_alloc(newFont->dataSize, STR_FONTDATA);
-	if (!newFont->pixData)
-		error_show(FL, 'OOM!', "font pix data");
 
 	fontFile.read(newFont->pixData, newFont->dataSize);
 
diff --git a/engines/m4/graphics/gr_sprite.cpp b/engines/m4/graphics/gr_sprite.cpp
index be65e32c55f..95c49b2b925 100644
--- a/engines/m4/graphics/gr_sprite.cpp
+++ b/engines/m4/graphics/gr_sprite.cpp
@@ -57,8 +57,7 @@ static uint8 scale_sprite(Buffer *S, Buffer *D, uint32 ScaleX, uint32 ScaleY) {
 
 	/* allocate 'scaled' buffer */
 	uint8 *pScaled = (uint8 *)mem_alloc(D->h * D->stride, "scaled buffer");
-	if (!pScaled)
-		error_show(FL, 'OOM!', "scaled buffer h:%uld w:%uld", D->h, D->stride);
+
 	D->data = pScaled;
 	
 	uint16 ErrY = 50;
@@ -120,8 +119,7 @@ uint8 gr_sprite_draw(DrawRequest *drawReq) {
 	// Check for RLE encoding in case of shadows
 	// There is no RLE shadow draw routine, so we have to decode shadows ahead of time.
 	if ((source.encoding & RLE8) && (source.encoding & SHADOW)) {
-		if (!(shadowBuff = (uint8 *)mem_alloc(source.stride * source.h, "shadow buff")))
-			error_show(FL, 'OOM!', "buffer w:%uld, h:%uld", source.w, source.h);
+		shadowBuff = (uint8 *)mem_alloc(source.stride * source.h, "shadow buff");
 
 		RLE8Decode(source.data, shadowBuff, source.stride);
 		source.data = shadowBuff;
@@ -134,8 +132,7 @@ uint8 gr_sprite_draw(DrawRequest *drawReq) {
 		// Check if input is RLE8 encoded
 		// If it's scaled we decode it first
 		if (Rle) {
-			if (!(scaledBuff = (uint8 *)mem_alloc(source.stride * source.h, "scaled buffer")))
-				error_show(FL, 'OOM!', "no mem: buffer w:%d, h:%d", source.w, source.h);
+			scaledBuff = (uint8 *)mem_alloc(source.stride * source.h, "scaled buffer");
 
 			RLE8Decode(source.data, scaledBuff, source.stride);
 			source.data = scaledBuff;
@@ -244,16 +241,11 @@ uint32 gr_sprite_RLE8_encode(Buffer *Source, Buffer *Dest) {
 	Dest->encoding = RLE8;
 	Dest->stride = Source->stride;
 	Dest->data = (uint8 *)mem_alloc(Source->h * OutBuffSize(Source->stride), "sprite data");
-	
-	if (!Dest->data) {
-		return 0;
-	}
 
 	for (i = 0; i < Source->h - 1; ++i)
 		Offset += EncodeScan(Source->data + i * Source->stride, Dest->data + Offset, Source->w, EOL);
 
 	Offset += EncodeScan(Source->data + i * Source->stride, Dest->data + Offset, Source->w, EOB);
-
 	Dest->data = (uint8 *)mem_realloc(Dest->data, Offset, "rle8 sprite data");
 
 	return Offset;
diff --git a/engines/m4/gui/game_menu.cpp b/engines/m4/gui/game_menu.cpp
index 1291b62b78d..350ded3ebfc 100644
--- a/engines/m4/gui/game_menu.cpp
+++ b/engines/m4/gui/game_menu.cpp
@@ -168,9 +168,6 @@ Sprite *SaveLoadMenuBase::menu_CreateThumbnail(int32 *spriteSize) {
 
 	// Create a Sprite for the thumbNail
 	Sprite *thumbNailSprite = (Sprite *)mem_alloc(sizeof(Sprite), "sprite");
-	if (thumbNailSprite == nullptr) {
-		return nullptr;
-	}
 
 	GrBuff *thumbNail = new GrBuff((MAX_VIDEO_X + 1) / 3, (MAX_VIDEO_Y + 1) / 3);
 	Buffer *destBuff = thumbNail->get_buffer();
diff --git a/engines/m4/gui/gui_cheapo.cpp b/engines/m4/gui/gui_cheapo.cpp
index f6709aef5ec..a0338a71292 100644
--- a/engines/m4/gui/gui_cheapo.cpp
+++ b/engines/m4/gui/gui_cheapo.cpp
@@ -118,10 +118,8 @@ void TextField::set_string(const char *string) {
 	int16 string_len = (int16)(cstrlen(string) + 1);
 	if (_string == nullptr) {
 		_string = (char *)mem_alloc(string_len, "string");
-	} else {
-		if (_string_len < string_len) {
-			_string = (char *)mem_realloc(_string, string_len, "string");
-		}
+	} else if (_string_len < string_len) {
+		_string = (char *)mem_realloc(_string, string_len, "string");
 	}
 
 	if (!_string)
diff --git a/engines/m4/gui/gui_dialog.cpp b/engines/m4/gui/gui_dialog.cpp
index eff58ada22b..0da093b46f8 100644
--- a/engines/m4/gui/gui_dialog.cpp
+++ b/engines/m4/gui/gui_dialog.cpp
@@ -141,12 +141,9 @@ void vmng_TextScrn_Destroy(TextScrn *myTextScrn) {
 }
 
 Dialog *DialogCreateAbsolute(int32 x1, int32 y1, int32 x2, int32 y2, uint32 scrnFlags) {
-	Dialog *dialog;
 	ButtonDrawRec bdr;
 
-	if ((dialog = (Dialog *)mem_alloc(sizeof(Dialog), STR_DIALOG)) == nullptr) {
-		return nullptr;
-	}
+	Dialog *dialog = (Dialog *)mem_alloc(sizeof(Dialog), STR_DIALOG);
 
 	dialog->w = x2 - x1 + 1;
 	dialog->h = y2 - y1 + 1;
@@ -1301,9 +1298,6 @@ TextScrn *TextScrn_Create(int32 x1, int32 y1, int32 x2, int32 y2, int32 luminanc
 
 	TextScrn *myTextScrn = (TextScrn *)mem_alloc(sizeof(TextScrn), STR_TEXTSCRN);
 
-	if (myTextScrn == nullptr)
-		return nullptr;
-
 	myTextScrn->w = x2 - x1 + 1;
 	myTextScrn->h = y2 - y1 + 1;
 	myTextScrn->textColor = textColor;
@@ -1349,8 +1343,6 @@ bool TextScrn_Add_TextItem(TextScrn *myTextScrn, int32 x, int32 y, int32 tag,
 	}
 
 	TextItem *myTextItem = (TextItem *)mem_alloc(sizeof(TextItem), "text item");
-	if (myTextItem == nullptr)
-		return false;
 
 	myTextItem->w = gr_font_string_width(prompt, 0); // No auto spacing
 	myTextItem->h = gr_font_get_height() + 1;
@@ -1388,8 +1380,6 @@ bool TextScrn_Add_Message(TextScrn *myTextScrn, int32 x, int32 y, int32 tag,
 		return false;
 	}
 	TextItem *myTextItem = (TextItem *)mem_alloc(sizeof(TextItem), "textscrn msg");
-	if (myTextItem == nullptr)
-		return false;
 
 	myTextItem->w = gr_font_string_width(prompt, 0); // No auto spacing
 	myTextItem->h = gr_font_get_height() + 1;
diff --git a/engines/m4/gui/gui_item.cpp b/engines/m4/gui/gui_item.cpp
index 92cb7022df8..5b2e428192d 100644
--- a/engines/m4/gui/gui_item.cpp
+++ b/engines/m4/gui/gui_item.cpp
@@ -266,16 +266,12 @@ bool InitItems() {
 
 Item *Item_create(Item *parent, enum ItemType type, int32 tag, M4CALLBACK cb) {
 	Item *temp = (Item *)mem_alloc(sizeof(Item), STR_ITEM);
-	if (temp == nullptr)
-		return nullptr;
 
 	temp->callback = cb;
 	temp->type = type;
 	temp->prompt = nullptr;
-
 	temp->tag = tag;
 	temp->x = temp->y = temp->w = temp->h = 0;
-
 	temp->myList = nullptr;
 
 	// add to end of list
@@ -635,8 +631,6 @@ bool ListItemAdd(Item *myItem, char *prompt, int32 listTag, int32 addMode, ListI
 		newListItem = changedItem;
 	else {
 		newListItem = (ListItem *)mem_alloc(sizeof(ListItem), STR_LIST);
-		if (newListItem == nullptr)
-			return false;
 
 		Common::strlcpy(newListItem->prompt, prompt, 80);
 		newListItem->tag = listTag;
diff --git a/engines/m4/gui/gui_menu_items.cpp b/engines/m4/gui/gui_menu_items.cpp
index 790522b78f6..7277924d3af 100644
--- a/engines/m4/gui/gui_menu_items.cpp
+++ b/engines/m4/gui/gui_menu_items.cpp
@@ -120,29 +120,18 @@ bool guiMenu::initialize(RGB8 *myPalette) {
 	_GM(menuFont) = gr_font_load("FONTMENU.FNT");
 
 	// Alloc space for the save/load tables
-	if ((_GM(slotTitles) = (char **)mem_alloc(sizeof(char *) * MAX_SLOTS, "slot desc array")) == nullptr) {
-		return false;
-	}
+	_GM(slotTitles) = (char **)mem_alloc(sizeof(char *) * MAX_SLOTS, "slot desc array");
+
 	for (i = 0; i < MAX_SLOTS; i++) {
-		if ((_GM(slotTitles)[i] = (char *)mem_alloc(80, "slot title")) == nullptr) {
-			return false;
-		}
+		_GM(slotTitles)[i] = (char *)mem_alloc(80, "slot title");
 	}
 	_GM(slotInUse) = (bool *)mem_alloc(sizeof(bool) * MAX_SLOTS, "slotUnUse array");
-	if (_GM(slotInUse) == nullptr) {
-		return false;
-	}
 
 	// Allocate space for the thumbnail sprites
 	_GM(thumbNails) = (Sprite **)mem_alloc(sizeof(Sprite *) * MAX_SLOTS, "thumbNail array");
-	if (_GM(thumbNails) == nullptr) {
-		return false;
-	}
+
 	for (i = 0; i < MAX_SLOTS; i++) {
 		_GM(thumbNails)[i] = (Sprite *)mem_alloc(sizeof(Sprite), "thumbNail");
-		if (_GM(thumbNails)[i] == nullptr) {
-			return false;
-		}
 		_GM(thumbNails)[i]->sourceHandle = nullptr;
 	}
 
@@ -614,15 +603,11 @@ bool guiMenu::loadSprites(const char *series, int32 numSprites) {
 	_GM(spriteCount) = numSprites;
 
 	// Create the _GM(menuSprites) array
-	if ((_GM(menuSprites) = (Sprite **)mem_alloc(sizeof(Sprite *) * _GM(spriteCount), "sprites array")) == nullptr) {
-		return false;
-	}
+	_GM(menuSprites) = (Sprite **)mem_alloc(sizeof(Sprite *) * _GM(spriteCount), "sprites array");
 
 	// Create the menu sprites
 	for (int32 i = 0; i < _GM(spriteCount); i++) {
-		if ((_GM(menuSprites)[i] = CreateSprite(_GM(menuSeriesHandle), _GM(menuSeriesOffset), i, nullptr, nullptr)) == nullptr) {
-			return false;
-		}
+		_GM(menuSprites)[i] = CreateSprite(_GM(menuSeriesHandle), _GM(menuSeriesOffset), i, nullptr, nullptr);
 	}
 
 	return true;
@@ -2210,13 +2195,11 @@ menuItemTextField *menuItemTextField::add(guiMenu *myMenu, int32 tag, int32 x, i
 	}
 
 	menuItemTextField *textInfo = (menuItemTextField *)mem_alloc(sizeof(menuItemTextField), "menu item textfield");
-	if (textInfo == nullptr) {
-		return nullptr;
-	}
-	textInfo->itemFlags = initFlags;
 
+	textInfo->itemFlags = initFlags;
 	textInfo->specialTag = specialTag;
 	textInfo->pixWidth = w - 27;
+
 	if (prompt) {
 		Common::strcpy_s(&textInfo->prompt[0], 80, prompt);
 		textInfo->promptEnd = &textInfo->prompt[strlen(prompt)];
diff --git a/engines/m4/gui/gui_mouse.cpp b/engines/m4/gui/gui_mouse.cpp
index 06f58eadc37..9b2d24792fc 100644
--- a/engines/m4/gui/gui_mouse.cpp
+++ b/engines/m4/gui/gui_mouse.cpp
@@ -32,19 +32,14 @@ namespace M4 {
 static void transShow(void *s, void *r, void *b, int32 destX, int32 destY);
 
 bool gui_mouse_init() {
-	_G(mouseBuffer).data = nullptr;
-	if ((_G(mouseBuffer).data = (uint8 *)mem_alloc(32 * 32, "mouse graphic")) == nullptr) {
-		return false;
-	}
+	_G(mouseBuffer).data = (uint8 *)mem_alloc(32 * 32, "mouse graphic");
 	_G(mouseBuffer).w = 32;
 	_G(mouseBuffer).stride = 32;
 	_G(mouseBuffer).h = 32;
 
 	auto &mouseSprite = _G(mouseSprite);
 	if (!mouseSprite) {
-		if ((mouseSprite = (M4sprite *)mem_alloc(sizeof(M4sprite), "mouse sprite")) == nullptr) {
-			return false;
-		}
+		mouseSprite = (M4sprite *)mem_alloc(sizeof(M4sprite), "mouse sprite");
 
 		mouseSprite->x = 0;
 		mouseSprite->y = 0;
@@ -63,9 +58,7 @@ bool gui_mouse_init() {
 		_G(mouseY2offset) = mouseSprite->h - _G(mouseY1offset) - 1;
 	}
 
-	if ((_G(mouseScreenSource) = (transSprite *)mem_alloc(sizeof(transSprite), "mouse transSprite")) == nullptr) {
-		return false;
-	}
+	_G(mouseScreenSource) = (transSprite *)mem_alloc(sizeof(transSprite), "mouse transSprite");
 
 	_G(mouseScreenSource)->srcSprite = mouseSprite;
 	_G(mouseScreenSource)->scrnBuffer = &_G(mouseBuffer);
diff --git a/engines/m4/gui/gui_sys.cpp b/engines/m4/gui/gui_sys.cpp
index 62be33ada4f..aeadc07b366 100644
--- a/engines/m4/gui/gui_sys.cpp
+++ b/engines/m4/gui/gui_sys.cpp
@@ -189,9 +189,7 @@ void AddSystemHotkey(int32 myKey, HotkeyCB callback) {
 	if (myHotkey) {
 		myHotkey->callback = callback;
 	} else {
-		if ((myHotkey = (Hotkey *)mem_alloc(sizeof(Hotkey), "hotkey")) == nullptr) {
-			return;
-		}
+		myHotkey = (Hotkey *)mem_alloc(sizeof(Hotkey), "hotkey");
 
 		myHotkey->myKey = myKey;
 		myHotkey->callback = callback;
diff --git a/engines/m4/gui/gui_vmng_screen.cpp b/engines/m4/gui/gui_vmng_screen.cpp
index 6617490b9d3..6fa178f5aa6 100644
--- a/engines/m4/gui/gui_vmng_screen.cpp
+++ b/engines/m4/gui/gui_vmng_screen.cpp
@@ -219,8 +219,6 @@ bool AddScreenHotkey(void *scrnContent, int32 myKey, HotkeyCB callback) {
 		return false;
 
 	Hotkey *myHotkey = (Hotkey *)mem_alloc(sizeof(Hotkey), "hotkey");
-	if (myHotkey == nullptr)
-		return false;
 
 	myHotkey->myKey = myKey;
 	myHotkey->callback = callback;
diff --git a/engines/m4/mem/mem.cpp b/engines/m4/mem/mem.cpp
index cdce0ab0f06..b641f6d7a04 100644
--- a/engines/m4/mem/mem.cpp
+++ b/engines/m4/mem/mem.cpp
@@ -66,9 +66,7 @@ bool mem_register_stash_type(int32 *memType, int32 blockSize, int32 maxNumReques
 			maxNumRequests = MAX_REQUESTS;
 
 		_G(requests)[i] = maxNumRequests;
-
 		_G(memBlock)[i] = mem_alloc((blockSize + sizeof(uintptr)) * maxNumRequests, name.c_str());
-		memset(_G(memBlock)[i], 0, (blockSize + sizeof(uintptr)) * maxNumRequests);
 
 		return true;
 	}
@@ -90,10 +88,9 @@ void mem_free_to_stash(void *mem, int32 memType) {
 }
 
 void *mem_get_from_stash(int32 memType, const Common::String &name) {
-	int i;
 	int8 *b_ptr = (int8 *)_G(memBlock)[memType];
 
-	for (i = 0; i < _G(requests)[memType]; i++) {
+	for (int i = 0; i < _G(requests)[memType]; i++) {
 		if (!*(uintptr *)b_ptr) {
 			*(uintptr *)b_ptr = 1;
 			void *result = (void *)(b_ptr + sizeof(uintptr));
@@ -119,8 +116,6 @@ char *mem_strdup(const char *str) {
 	}
 
 	new_str = (char *)mem_alloc(strlen(str) + 1, "string");
-	if (!new_str)
-		return nullptr;
 
 	Common::strcpy_s(new_str, 256, str);
 	return new_str;
diff --git a/engines/m4/mem/memman.h b/engines/m4/mem/memman.h
index 45db0749a92..3bee9e53cba 100644
--- a/engines/m4/mem/memman.h
+++ b/engines/m4/mem/memman.h
@@ -23,14 +23,18 @@
 #define M4_MEM_MEMMAN_H
 
 #include "common/algorithm.h"
+#include "m4/core/errors.h"
 #include "m4/m4_types.h"
 
 namespace M4 {
 
 #define _MEMTYPE_LIMIT 33
 
-inline Handle mem_alloc(size_t size, const char *) {
+inline Handle mem_alloc(size_t size, const char *detail) {
 	byte *ptr = (byte *)malloc(size);
+	if (!ptr)
+		error_show(FL, 'OOM!', "mem_alloc() - couldn't allocate %ld bytes - %s", size, detail);
+	
 	Common::fill(ptr, ptr + size, 0);
 	return (Handle)ptr;
 }
diff --git a/engines/m4/platform/tile/tile_read.cpp b/engines/m4/platform/tile/tile_read.cpp
index dac3ab1dea9..116d2b0da03 100644
--- a/engines/m4/platform/tile/tile_read.cpp
+++ b/engines/m4/platform/tile/tile_read.cpp
@@ -28,9 +28,8 @@ namespace M4 {
 
 void tt_read_header(SysFile *ifp, int32 *file_x, int32 *file_y,
 	int32 *num_x_tiles, int32 *num_y_tiles, int32 *tile_x, int32 *tile_y, RGB8 *pal) {
-	int32 value;
 
-	// Initalize return parameters
+	// Initialize return parameters
 	*num_x_tiles = 0;
 	*num_y_tiles = 0;
 	*tile_x = 0;
@@ -54,7 +53,7 @@ void tt_read_header(SysFile *ifp, int32 *file_x, int32 *file_y,
 
 	// Write color table
 	for (int i = 0; i < 256; i++) {
-		value = ifp->readSint32LE();
+		const int32 value = ifp->readSint32LE();
 
 		pal[i].r = (value >> 16) & 0x0ff;
 		pal[i].g = (value >> 8) & 0x0ff;
@@ -63,13 +62,8 @@ void tt_read_header(SysFile *ifp, int32 *file_x, int32 *file_y,
 }
 
 Buffer *tt_read(SysFile *ifp, int index, int32 tile_x, int32 tile_y) {
-	int32 tile_size;
-	int offset;
 	Buffer *out = (Buffer *)mem_alloc(sizeof(Buffer), "tile buffer");
 
-	if (!out)
-		error_show(FL, 'OOM!', "fail to allocate mem for buffer structure");
-
 	out->data = nullptr;
 	out->w = 0;
 	out->stride = 0;
@@ -79,7 +73,7 @@ Buffer *tt_read(SysFile *ifp, int index, int32 tile_x, int32 tile_y) {
 	if (index < 0)
 		error_show(FL, 'TILI');
 
-	tile_size = tile_x * tile_y;
+	const int32 tile_size = tile_x * tile_y;
 
 	if (index == 0) {
 		// First tile data
@@ -87,7 +81,7 @@ Buffer *tt_read(SysFile *ifp, int index, int32 tile_x, int32 tile_y) {
 			error_show(FL, 'FNF!', ".TT file");
 
 		// Read data of tiles to file
-		offset = index * tile_size + 256 * 4 + 32; // Get rid of color table and header stuff
+		const int offset = index * tile_size + 256 * 4 + 32; // Get rid of color table and header stuff
 		ifp->seek((uint32)offset);
 	}
 
diff --git a/engines/m4/wscript/ws_cruncher.cpp b/engines/m4/wscript/ws_cruncher.cpp
index a965c216e6f..71acf90175b 100644
--- a/engines/m4/wscript/ws_cruncher.cpp
+++ b/engines/m4/wscript/ws_cruncher.cpp
@@ -134,8 +134,7 @@ bool ws_InitCruncher(void) {
 	if (_GWS(memtypeEOS) < 0)
 		error_show(FL, 'WSCE');
 
-	if ((_GWS(myCruncher) = (cruncher *)mem_alloc(sizeof(cruncher), "cruncher")) == nullptr)
-		error_show(FL, 'OOM!', "%d bytes.", sizeof(cruncher));
+	_GWS(myCruncher) = (cruncher *)mem_alloc(sizeof(cruncher), "cruncher");
 
 	_GWS(myCruncher)->backLayerAnim8 = nullptr;
 	_GWS(myCruncher)->frontLayerAnim8 = nullptr;
@@ -144,9 +143,8 @@ bool ws_InitCruncher(void) {
 
 	// Set up stack
 	_GWS(stackSize) = 2048;
-	if ((_GWS(stackBase) = (uint32 *)mem_alloc(_GWS(stackSize), "crunchstack")) == nullptr) {
-		error_show(FL, 'OOM!', "%d bytes.", _GWS(stackSize));
-	}
+	_GWS(stackBase) = (uint32 *)mem_alloc(_GWS(stackSize), "crunchstack");
+
 	_GWS(stackTop) = _GWS(stackBase);
 	_GWS(stackLimit) = (uint32 *)((byte *)_GWS(stackBase) + (uint32)_GWS(stackSize));
 
@@ -181,10 +179,6 @@ Anim8 *ws_AddAnim8ToCruncher(machine *m, int32 sequHash) {
 
 	// Allocate an anim8 structure
 	Anim8 *myAnim8 = (Anim8 *)mem_alloc(sizeof(Anim8), "Anim8");
-	if (myAnim8 == nullptr) {
-		ws_LogErrorMsg(FL, "Out of memory - mem requested: %d.", sizeof(Anim8));
-		return nullptr;
-	}
 
 	// Find the sequence
 	int32 numLocalVars;
@@ -196,10 +190,6 @@ Anim8 *ws_AddAnim8ToCruncher(machine *m, int32 sequHash) {
 
 	// Allocate an array of registers
 	frac16 *my_regs = (frac16 *)mem_alloc(sizeof(frac16) * (IDX_COUNT + numLocalVars), "Anim8 regs");
-	if (my_regs == nullptr) {
-		ws_LogErrorMsg(FL, "Out of memory - mem requested: %d.", sizeof(frac16) * (IDX_COUNT + numLocalVars));
-		return nullptr;
-	}
 
 	// Initialize the Anim8 structure
 	myAnim8->active = true;
@@ -927,13 +917,8 @@ static void op_SETCEL(Anim8 *myAnim8) {
 
 	if (!myAnim8->myCCB) {
 		// Allocate and initialize a CCB structure
-		if ((myAnim8->myCCB = (CCB *)mem_alloc(sizeof(CCB), "CCB")) == nullptr) {
-			ws_LogErrorMsg(FL, "Out of memory - mem requested: %d bytes.", sizeof(CCB));
-			ws_Error(myAnim8->myMachine, ERR_SEQU, 0x02fe, "setcel() failed.");
-		}
-		if (!InitCCB(myAnim8->myCCB)) {
-			ws_Error(myAnim8->myMachine, ERR_SEQU, 0x025d, "setcel() failed.");
-		}
+		myAnim8->myCCB = (CCB *)mem_alloc(sizeof(CCB), "CCB");
+		InitCCB(myAnim8->myCCB);
 	}
 
 	CCB *myCCB = myAnim8->myCCB;
@@ -1233,13 +1218,8 @@ static void op_OPEN_STREAM_SS(Anim8 *myAnim8) {
 
 	if (!myAnim8->myCCB) {
 		// Allocate and initialize a CCB structure
-		if ((myAnim8->myCCB = (CCB *)mem_alloc(sizeof(CCB), "CCB")) == nullptr) {
-			ws_LogErrorMsg(FL, "Out of memory - mem requested: %d.", sizeof(CCB));
-			ws_Error(myAnim8->myMachine, ERR_SEQU, 0x02fe, "open_ss_stream() failed.");
-		}
-		if (!InitCCB(myAnim8->myCCB)) {
-			ws_Error(myAnim8->myMachine, ERR_SEQU, 0x025d, "open_ss_stream() failed.");
-		}
+		myAnim8->myCCB = (CCB *)mem_alloc(sizeof(CCB), "CCB");
+		InitCCB(myAnim8->myCCB);
 	}
 
 	CCB *myCCB = myAnim8->myCCB;
diff --git a/engines/m4/wscript/ws_hal.cpp b/engines/m4/wscript/ws_hal.cpp
index e1d8adbea36..bf4badeb274 100644
--- a/engines/m4/wscript/ws_hal.cpp
+++ b/engines/m4/wscript/ws_hal.cpp
@@ -481,19 +481,17 @@ void GetBezPoint(frac16 *x, frac16 *y, frac16 *coeffs, frac16 tVal) {
 				MulSF16(tVal, coeffs[1])))));
 }
 
-bool InitCCB(CCB *myCCB) {
+void InitCCB(CCB *myCCB) {
 	myCCB->flags = CCB_SKIP;
 	myCCB->source = nullptr;
-	if ((myCCB->currLocation = (M4Rect *)mem_alloc(sizeof(M4Rect), "Rectangle")) == nullptr) {
-		return false;
-	}
+	myCCB->currLocation = (M4Rect *)mem_alloc(sizeof(M4Rect), "Rectangle");
+
 	myCCB->currLocation->x1 = -1;
 	myCCB->currLocation->y1 = -1;
 	myCCB->currLocation->x2 = -1;
 	myCCB->currLocation->y2 = -1;
-	if ((myCCB->newLocation = (M4Rect *)mem_alloc(sizeof(M4Rect), "Rectangle")) == nullptr) {
-		return false;
-	}
+	myCCB->newLocation = (M4Rect *)mem_alloc(sizeof(M4Rect), "Rectangle");
+
 	myCCB->newLocation->x1 = -1;
 	myCCB->newLocation->y1 = -1;
 	myCCB->newLocation->x2 = -1;
@@ -508,7 +506,6 @@ bool InitCCB(CCB *myCCB) {
 	myCCB->myStream = nullptr;
 	myCCB->seriesName = nullptr;
 
-	return true;
 }
 
 void HideCCB(CCB *myCCB) {
@@ -544,9 +541,8 @@ void MoveCCB(CCB *myCCB, frac16 deltaX, frac16 deltaY) {
 
 	if (myCCB->flags & CCB_STREAM) {
 		if (!myCCB->maxArea) {
-			if ((myCCB->maxArea = (M4Rect *)mem_alloc(sizeof(M4Rect), "Rectangle")) == nullptr) {
-				error_show(FL, 'OOM!');
-			}
+			myCCB->maxArea = (M4Rect *)mem_alloc(sizeof(M4Rect), "Rectangle");
+
 			myCCB->maxArea->x1 = myCCB->newLocation->x1;
 			myCCB->maxArea->y1 = myCCB->newLocation->y1;
 			myCCB->maxArea->x2 = myCCB->newLocation->x2;
@@ -624,9 +620,8 @@ void Cel_msr(Anim8 *myAnim8) {
 		myCCB->scaleX, myCCB->scaleY, myCCB->source->w, myCCB->source->h, myCCB->newLocation);
 	if (myCCB->flags & CCB_STREAM) {
 		if (!myCCB->maxArea) {
-			if ((myCCB->maxArea = (M4Rect *)mem_alloc(sizeof(M4Rect), "Rectangle")) == nullptr) {
-				error_show(FL, 'OOM!');
-			}
+			myCCB->maxArea = (M4Rect *)mem_alloc(sizeof(M4Rect), "Rectangle");
+
 			myCCB->maxArea->x1 = myCCB->newLocation->x1;
 			myCCB->maxArea->y1 = myCCB->newLocation->y1;
 			myCCB->maxArea->x2 = myCCB->newLocation->x2;
diff --git a/engines/m4/wscript/ws_hal.h b/engines/m4/wscript/ws_hal.h
index 08da269491d..57966ab14c5 100644
--- a/engines/m4/wscript/ws_hal.h
+++ b/engines/m4/wscript/ws_hal.h
@@ -53,7 +53,7 @@ void ws_hal_RefreshWoodscriptBuffer(cruncher *myCruncher, Buffer *background,
 	int16 *depth_table, Buffer *screenCodes, uint8 *myPalette, uint8 *ICT);
 void GetBezCoeffs(frac16 *ctrlPoints, frac16 *coeffs);
 void GetBezPoint(frac16 *x, frac16 *y, frac16 *coeffs, frac16 tVal);
-bool InitCCB(CCB *myCCB);
+void InitCCB(CCB *myCCB);
 void HideCCB(CCB *myCCB);
 void ShowCCB(CCB *myCCB);
 //void SetLastCCB(CCB *myCCB);
diff --git a/engines/m4/wscript/ws_load.cpp b/engines/m4/wscript/ws_load.cpp
index 6a44d8e3053..972d8e98c13 100644
--- a/engines/m4/wscript/ws_load.cpp
+++ b/engines/m4/wscript/ws_load.cpp
@@ -95,15 +95,10 @@ bool InitWSAssets() {
 	}
 
 	// Allocate space for the tables used by the loader and the resource io MACHine tables
-	if ((_GWS(globalMACHnames) = (char **)mem_alloc(sizeof(char *) * 256, "MACH resource table")) == nullptr) {
-		return false;
-	}
-	if ((_GWS(globalMACHHandles) = (MemHandle *)mem_alloc(sizeof(MemHandle) * 256, "CELS Handles table")) == nullptr) {
-		return false;
-	}
-	if ((_GWS(globalMACHoffsets) = (int32 *)mem_alloc(sizeof(int32) * 256, "MACH offsets table")) == nullptr) {
-		return false;
-	}
+	_GWS(globalMACHnames) = (char **)mem_alloc(sizeof(char *) * 256, "MACH resource table");
+	_GWS(globalMACHHandles) = (MemHandle *)mem_alloc(sizeof(MemHandle) * 256, "CELS Handles table");
+	_GWS(globalMACHoffsets) = (int32 *)mem_alloc(sizeof(int32) * 256, "MACH offsets table");
+
 	for (i = 0; i < 256; i++) {
 		_GWS(globalMACHnames)[i] = nullptr;
 		_GWS(globalMACHHandles)[i] = nullptr;
@@ -111,15 +106,10 @@ bool InitWSAssets() {
 	}
 
 	// SEQUence tables
-	if ((_GWS(globalSEQUnames) = (char **)mem_alloc(sizeof(char *) * 256, "SEQU resource table")) == nullptr) {
-		return false;
-	}
-	if ((_GWS(globalSEQUHandles) = (MemHandle *)mem_alloc(sizeof(MemHandle) * 256, "CELS Handles table")) == nullptr) {
-		return false;
-	}
-	if ((_GWS(globalSEQUoffsets) = (int32 *)mem_alloc(sizeof(int32) * 256, "SEQU offsets table")) == nullptr) {
-		return false;
-	}
+	_GWS(globalSEQUnames) = (char **)mem_alloc(sizeof(char *) * 256, "SEQU resource table");
+	_GWS(globalSEQUHandles) = (MemHandle *)mem_alloc(sizeof(MemHandle) * 256, "CELS Handles table");
+	_GWS(globalSEQUoffsets) = (int32 *)mem_alloc(sizeof(int32) * 256, "SEQU offsets table");
+	
 	for (i = 0; i < 256; i++) {
 		_GWS(globalSEQUnames)[i] = nullptr;
 		_GWS(globalSEQUHandles)[i] = nullptr;
@@ -127,15 +117,10 @@ bool InitWSAssets() {
 	}
 
 	// DATA tables
-	if ((_GWS(globalDATAnames) = (char **)mem_alloc(sizeof(char *) * 256, "DATA resource table")) == nullptr) {
-		return false;
-	}
-	if ((_GWS(globalDATAHandles) = (MemHandle *)mem_alloc(sizeof(MemHandle) * 256, "CELS Handles table")) == nullptr) {
-		return false;
-	}
-	if ((_GWS(globalDATAoffsets) = (int32 *)mem_alloc(sizeof(int32) * 256, "DATA offsets table")) == nullptr) {
-		return false;
-	}
+	_GWS(globalDATAnames) = (char **)mem_alloc(sizeof(char *) * 256, "DATA resource table");
+	_GWS(globalDATAHandles) = (MemHandle *)mem_alloc(sizeof(MemHandle) * 256, "CELS Handles table");
+	_GWS(globalDATAoffsets) = (int32 *)mem_alloc(sizeof(int32) * 256, "DATA offsets table");
+
 	for (i = 0; i < 256; i++) {
 		_GWS(globalDATAnames)[i] = nullptr;
 		_GWS(globalDATAHandles)[i] = nullptr;
@@ -143,18 +128,11 @@ bool InitWSAssets() {
 	}
 
 	// CELS tables
-	if ((_GWS(globalCELSnames) = (char **)mem_alloc(sizeof(char *) * 256, "CELS resource table")) == nullptr) {
-		return false;
-	}
-	if ((_GWS(globalCELSHandles) = (MemHandle *)mem_alloc(sizeof(MemHandle) * 256, "CELS Handles table")) == nullptr) {
-		return false;
-	}
-	if ((_GWS(globalCELSoffsets) = (int32 *)mem_alloc(sizeof(int32) * 256, "CELS offsets table")) == nullptr) {
-		return false;
-	}
-	if ((_GWS(globalCELSPaloffsets) = (int32 *)mem_alloc(sizeof(int32) * 256, "CELS pal offsets table")) == nullptr) {
-		return false;
-	}
+	_GWS(globalCELSnames) = (char **)mem_alloc(sizeof(char *) * 256, "CELS resource table");
+	_GWS(globalCELSHandles) = (MemHandle *)mem_alloc(sizeof(MemHandle) * 256, "CELS Handles table");
+	_GWS(globalCELSoffsets) = (int32 *)mem_alloc(sizeof(int32) * 256, "CELS offsets table");
+	_GWS(globalCELSPaloffsets) = (int32 *)mem_alloc(sizeof(int32) * 256, "CELS pal offsets table");
+
 	for (i = 0; i < 256; i++) {
 		_GWS(globalCELSnames)[i] = nullptr;
 		_GWS(globalCELSHandles)[i] = nullptr;
@@ -507,10 +485,6 @@ M4sprite *CreateSprite(MemHandle resourceHandle, int32 handleOffset, int32 index
 
 	if (!mySprite) {
 		mySprite = (M4sprite *)mem_alloc(sizeof(M4sprite), "Sprite");
-		if (!mySprite) {
-			ws_LogErrorMsg(FL, "Out of memory - mem requested: %d.", sizeof(M4sprite));
-			return nullptr;
-		}
 	}
 
 	// Find the cels source  from the asset block
@@ -1144,24 +1118,18 @@ CCB *GetWSAssetCEL(uint32 hash, uint32 index, CCB *myCCB) {
 	//If a memory location to store the CCB has not been provided...
 	if (!myCCB) {
 		// Create the CCB struct
-		if ((myCCB = (CCB *)mem_alloc(sizeof(CCB), "CCB")) == nullptr) {
-			ws_LogErrorMsg(FL, "Out of memory - mem requested: %d bytes", sizeof(CCB));
-			return nullptr;
-		}
+		myCCB = (CCB *)mem_alloc(sizeof(CCB), "CCB");
 
 		// Create the CCB current location and new location rectangles
-		if ((myCCB->currLocation = (M4Rect *)mem_alloc(sizeof(M4Rect), "M4Rect")) == nullptr) {
-			ws_LogErrorMsg(FL, "Out of memory - mem requested: %d bytes", sizeof(M4Rect));
-			return nullptr;
-		}
+		myCCB->currLocation = (M4Rect *)mem_alloc(sizeof(M4Rect), "M4Rect");
+
 		myCCB->currLocation->x1 = 0;
 		myCCB->currLocation->y1 = 0;
 		myCCB->currLocation->x2 = 0;
 		myCCB->currLocation->y2 = 0;
-		if ((myCCB->newLocation = (M4Rect *)mem_alloc(sizeof(M4Rect), "M4Rect")) == nullptr) {
-			ws_LogErrorMsg(FL, "Out of memory - mem requested: %d bytes", sizeof(M4Rect));
-			return nullptr;
-		}
+
+		myCCB->newLocation = (M4Rect *)mem_alloc(sizeof(M4Rect), "M4Rect");
+		
 		myCCB->maxArea = nullptr;
 		myCCB->source = nullptr;
 	}
@@ -1523,16 +1491,11 @@ static int32 GetSSHeaderInfo(SysFile *sysFile, uint32 **data, RGB8 *myPalette) {
 		// If there is at least one color specified in this block
 		if (numColors > 0) {
 			uint32 *myColors = (uint32 *)mem_alloc(celsSize - 12, "ss pal info");
-			if (myColors == nullptr) {
-				ws_LogErrorMsg(FL, "Failed to mem_alloc() %d bytes.", celsSize - 12);
-				return -1;
-			}
 
 			// Read in the color info into a temp buffer
 			for (i = 0; i < numColors; ++i)
 				myColors[i] = sysFile->readUint32LE();
 
-
 			// If the chunk is in the wrong format, byte-swap the entire chunk
 			// note: we do this because we want the data stored in nrgb format
 			// The data is always read in low byte first, but we need it high byte first
@@ -1601,10 +1564,7 @@ static int32 GetSSHeaderInfo(SysFile *sysFile, uint32 **data, RGB8 *myPalette) {
 	}
 
 	// Allocate a block to hold both the series header, and the sprite offset table
-	if ((*data = (uint32 *)mem_alloc((SS_HEAD_SIZE + numCels) * 4, "ss header")) == nullptr) {
-		ws_LogErrorMsg(FL, "Failed to mem_alloc() %d bytes.", (SS_HEAD_SIZE + numCels) << 2);
-		return -1;
-	}
+	*data = (uint32 *)mem_alloc((SS_HEAD_SIZE + numCels) * 4, "ss header");
 
 	// Read in the series header and the sprite offset table
 	// Since we already read in celsType and celsSize, SS_HEAD_SIZE-2
@@ -1685,10 +1645,6 @@ bool ws_OpenSSstream(SysFile *sysFile, Anim8 *anim8) {
 
 	if (!myCCB->source) {
 		myCCB->source = (M4sprite *)mem_alloc(sizeof(M4sprite), "Sprite");
-		if (!myCCB->source) {
-			ws_LogErrorMsg(FL, "Failed to mem_alloc() %d bytes.", sizeof(M4sprite));
-			return false;
-		}
 	}
 
 	term_message("Biggest frame was: %d, size: %d bytes (compressed)", obesest_frame, maxFrameSize);
diff --git a/engines/m4/wscript/ws_machine.cpp b/engines/m4/wscript/ws_machine.cpp
index 1385182a382..fa3ff32394e 100644
--- a/engines/m4/wscript/ws_machine.cpp
+++ b/engines/m4/wscript/ws_machine.cpp
@@ -127,9 +127,7 @@ static void clear_persistent_msg_list(machine *m) {
 
 static msgRequest *new_msgRequest() {
 	msgRequest *newMsg = (msgRequest *)mem_alloc(sizeof(msgRequest), "msgRequest");
-	if (newMsg == nullptr) {
-		ws_LogErrorMsg(FL, "Failed to mem_alloc() %d bytes.", sizeof(msgRequest));
-	}
+
 	return newMsg;
 }
 
@@ -972,13 +970,6 @@ void IntoTheState(machine *m) {
 machine *TriggerMachineByHash(int32 myHash, Anim8 *parentAnim8, int32 dataHash, int32 dataRow, MessageCB CintrMsg, bool debug, const char *machName) {
 	machine *m = (machine *)mem_alloc(sizeof(machine), "machine");
 
-	if (m == nullptr) {
-		ws_LogErrorMsg(FL, "Out of memory - mem requested: %d.", sizeof(machine));
-		ws_LogErrorMsg(FL, "Trying to trigger hash: %d, name: %s", myHash, machName);
-		ws_Error(m, ERR_INTERNAL, 0x2fe, "TriggerMachineByHash() failed.");
-		return nullptr;
-	}
-
 	// Initialize the identification fields
 	_GWS(machineIDCount)++;
 	if (_GWS(machineIDCount) == DEAD_MACHINE_ID) {
@@ -1174,10 +1165,7 @@ void sendWSMessage(uint32 msgHash, frac16 msgValue, machine *recvM,
 
 	// Prepare a global message structure
 	globalMsgReq *tempGlobalMsg = (globalMsgReq *)mem_alloc(sizeof(globalMsgReq), "globalMsgReq");
-	if (tempGlobalMsg == nullptr) {
-		ws_LogErrorMsg(FL, "Out of memory - mem requested: %d.", sizeof(machine));
-		ws_Error(nullptr, ERR_INTERNAL, 0x2fe, "SendWSMessage() failed.");
-	}
+
 	tempGlobalMsg->msgHash = msgHash;
 	tempGlobalMsg->msgValue = msgValue;
 	tempGlobalMsg->machHash = machHash;




More information about the Scummvm-git-logs mailing list