From f5cd1d5ebcb565f2a9944d78b4026db36555081f Mon Sep 17 00:00:00 2001
From: Alam Ed Arias <alam@srb2.org>
Date: Sat, 10 Jan 2015 17:26:29 -0500
Subject: [PATCH] add check on write failed in old TGA screenshot code

---
 src/hardware/hw_draw.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/src/hardware/hw_draw.c b/src/hardware/hw_draw.c
index 313bc6c2f3..e6a26e6058 100644
--- a/src/hardware/hw_draw.c
+++ b/src/hardware/hw_draw.c
@@ -726,7 +726,11 @@ static inline boolean saveTGA(const char *file_name, void *buffer,
 	tga_hdr.image_type = 2;
 	tga_hdr.image_descriptor = 32;
 
-	write(fd, &tga_hdr, sizeof (TGAHeader));
+	if ( -1 == write(fd, &tga_hdr, sizeof (TGAHeader)))
+	{
+		close(fd);
+		return false;
+	}
 	// format to 888 BGR
 	for (i = 0; i < width * height * 3; i+=3)
 	{
@@ -734,7 +738,11 @@ static inline boolean saveTGA(const char *file_name, void *buffer,
 		buf8[i] = buf8[i+2];
 		buf8[i+2] = temp;
 	}
-	write(fd, buffer, width * height * 3);
+	if ( -1 == write(fd, buffer, width * height * 3))
+	{
+		close(fd);
+		return false;
+	}
 	close(fd);
 	return true;
 }
-- 
GitLab