Cleaned up compiler warnings about unchecked return values. SDL-1.2
authorRyan C. Gordon <icculus@icculus.org>
Thu, 07 Jul 2011 11:49:46 -0700
branchSDL-1.2
changeset 5559 9f181779cfdd
parent 5550 80ae1ac3bdc9
child 5560 98ae43d3d2f4
Cleaned up compiler warnings about unchecked return values.
src/video/fbcon/SDL_fbevents.c
src/video/x11/SDL_x11modes.c
--- a/src/video/fbcon/SDL_fbevents.c	Sat Jun 04 15:34:32 2011 -0400
+++ b/src/video/fbcon/SDL_fbevents.c	Thu Jul 07 11:49:46 2011 -0700
@@ -359,9 +359,10 @@
 			SDL_snprintf(path, SDL_arraysize(path), "/proc/%s/status", entry->d_name);
 			status=fopen(path, "r");
 			if ( status ) {
+				int matches = 0;
 				name[0] = '\0';
-				fscanf(status, "Name: %s", name);
-				if ( SDL_strcmp(name, wanted_name) == 0 ) {
+				matches = fscanf(status, "Name: %s", name);
+				if ( (matches == 1) && (SDL_strcmp(name, wanted_name) == 0) ) {
 					pid = SDL_atoi(entry->d_name);
 				}
 				fclose(status);
@@ -479,7 +480,9 @@
 	tv.tv_usec = 0;
 	while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) {
 		char temp[32];
-		read(fd, temp, sizeof(temp));
+		if (read(fd, temp, sizeof(temp)) <= 0) {
+			break;
+		}
 	}
 
 	return retval;
@@ -508,7 +511,9 @@
 		tv.tv_usec = 0;
 		while ( select(fd+1, &fdset, 0, 0, &tv) > 0 ) {
 			char temp[32];
-			read(fd, temp, sizeof(temp));
+			if (read(fd, temp, sizeof(temp)) <= 0) {
+				break;
+			}
 		}
 
    		/* Query for the type of mouse protocol */
@@ -770,9 +775,7 @@
 	/* Figure out the mouse packet size */
 	switch (mouse_drv) {
 		case MOUSE_NONE:
-			/* Ack! */
-			read(mouse_fd, mousebuf, BUFSIZ);
-			return;
+			break;  /* carry on to read from device and discard it. */
 		case MOUSE_MSC:
 			packetsize = 5;
 			break;
@@ -812,14 +815,20 @@
 	if ( nread < 0 ) {
 		return;
 	}
+
+	if (mouse_drv == MOUSE_NONE) {
+		return;  /* we're done; just draining the input queue. */
+	}
+
 	nread += start;
 #ifdef DEBUG_MOUSE
 	fprintf(stderr, "Read %d bytes from mouse, start = %d\n", nread, start);
 #endif
+
 	for ( i=0; i<(nread-(packetsize-1)); i += packetsize ) {
 		switch (mouse_drv) {
-			case MOUSE_NONE:
-				break;
+			case MOUSE_NONE: /* shouldn't actually hit this. */
+				break;  /* just throw everything away. */
 			case MOUSE_MSC:
 				/* MSC protocol has 0x80 in high byte */
 				if ( (mousebuf[i] & 0xF8) != 0x80 ) {
--- a/src/video/x11/SDL_x11modes.c	Sat Jun 04 15:34:32 2011 -0400
+++ b/src/video/x11/SDL_x11modes.c	Thu Jul 07 11:49:46 2011 -0700
@@ -465,10 +465,13 @@
 
         metro_fp = fopen("/usr/X11R6/lib/X11/Metro/.version", "r");
         if ( metro_fp != NULL ) {
-            int major, minor, patch, version;
+            int major, minor, patch, version, scannum;
             major = 0; minor = 0; patch = 0;
-            fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch);
+            scannum = fscanf(metro_fp, "%d.%d.%d", &major, &minor, &patch);
             fclose(metro_fp);
+            if ( (scannum < 0) || (scannum > 3) ) {
+                return 0;  /* we need _something_ useful from fscanf(). */
+            }
             version = major*100+minor*10+patch;
             if ( version < 431 ) {
                 return 0;