File xbgi-grapherrormsg.diff of Package libXbgi

From: Jan Engelhardt <jengelh@inai.de>
Date: 2014-01-23 14:44:35.390427664 +0100

xbgi: resolve invocation of undefined behavior in grapherrormsg.c

rpmlint said:
I: Program is using uninitialized variables.
   Note the difference between "is used" and "may be used"
W: libXbgi uninitialized-variable grapherrormsg.c:78

gcc:
grapherrormsg.c: In function 'grapherrormsg':
grapherrormsg.c:78:2: warning: 'errormsg' is used uninitialized in this function [-Wuninitialized]
  return (errormsg);
  ^

Summary:
The value of errormsg is undefined. In particular, it is not
even guaranteed to have enough space to hold the strings copied
into it with strcpy.
Switch to constant string pointers.

---
 src/grapherrormsg.c |   42 +++++++++++++++++++++---------------------
 src/graphics.h      |    2 +-
 2 files changed, 22 insertions(+), 22 deletions(-)

Index: xbgi-364/src/grapherrormsg.c
===================================================================
--- xbgi-364.orig/src/grapherrormsg.c
+++ xbgi-364/src/grapherrormsg.c
@@ -11,65 +11,65 @@
 #include <string.h>
 #include "graphics.h"
 
-char *grapherrormsg(int errorcode)
+const char *grapherrormsg(int errorcode)
 {
 	enum graphics_errors gr_error;
-	char *errormsg;
+	const char *errormsg = "Unknown error";
 
 	gr_error = errorcode;
 	switch (gr_error) {
 		case grOk:
-			strcpy(errormsg, "No error");
+			errormsg = "No error";
 			break;
 		case grNoInitGraph:
-			strcpy(errormsg,
-			      "XBGI graphics not installed (use initgraph()).");
+			errormsg =
+			      "XBGI graphics not installed (use initgraph()).";
 			break;
 		case grNotDetected:
-			strcpy(errormsg, "Graphics hardware not detected.");
+			errormsg = "Graphics hardware not detected.";
 			break;
 		case grFileNotFound:
-			strcpy(errormsg, "Device driver file not found.");
+			errormsg = "Device driver file not found.";
 			break;
 		case grInvalidDriver:
-			strcpy(errormsg, "Invalid device driver file.");
+			errormsg = "Invalid device driver file.";
 			break;
 		case grNoLoadMem:
-			strcpy(errormsg, "Not enough memory to load driver.");
+			errormsg = "Not enough memory to load driver.";
 			break;
 		case grNoScanMem:
-			strcpy(errormsg, "Out of memory in scan fill.");
+			errormsg = "Out of memory in scan fill.";
 			break;
 		case grNoFloodMem:
-			strcpy(errormsg, "Out of memory in flood fill.");
+			errormsg = "Out of memory in flood fill.";
 			break;
 		case grFontNotFound:
-			strcpy(errormsg, "Font file not found.");
+			errormsg = "Font file not found.";
 			break;
 		case grNoFontMem:
-			strcpy(errormsg, "Not enough memory to load font.");
+			errormsg = "Not enough memory to load font.";
 			break;
 		case grInvalidMode:
-			strcpy(errormsg, "Invalid graphics mode for"
-				    "selected driver.");
+			errormsg = "Invalid graphics mode for"
+				    "selected driver.";
 			break;
 		case grError:
-			strcpy(errormsg, "Graphics error.");
+			errormsg = "Graphics error.";
 			break;
 		case grIOerror:
-			strcpy(errormsg, "Graphics I/O error.");
+			errormsg = "Graphics I/O error.";
 			break;
 		case grInvalidFont:
-			strcpy(errormsg, "Invalid font file.");
+			errormsg = "Invalid font file.";
 			break;
 		case grInvalidFontNum:
-			strcpy(errormsg, "Invalid font number.");
+			errormsg = "Invalid font number.";
 			break;
 		case grInvalidDeviceNum:
-			strcpy(errormsg, "Invalid device number.");
+			errormsg = "Invalid device number.";
 			break;
 		case grInvalidVersion:
-			strcpy(errormsg, "Invalid version of file.");
+			errormsg = "Invalid version of file.";
 			break;
 		default:
 			break;
Index: xbgi-364/src/graphics.h
===================================================================
--- xbgi-364.orig/src/graphics.h
+++ xbgi-364/src/graphics.h
@@ -325,7 +325,7 @@ typedef struct {
 		int getx PROTO((void));
 		int gety PROTO((void));
 		void graphdefaults PROTO((void));
-		char *grapherrormsg PROTO((int));
+		const char *grapherrormsg PROTO((int));
 		int graphresult PROTO((void));
 		unsigned int imagesize PROTO((int, int, int, int));
 		void initgraph PROTO((int *, int *, char *));
openSUSE Build Service is sponsored by