From 05fe5d4d621de98ffe8f285fcb581db45e5ec6d3 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Thu, 7 Jul 2011 11:49:46 -0700 Subject: [PATCH] Cleaned up compiler warnings about unchecked return values. --- src/video/fbcon/SDL_fbevents.c | 27 ++++++++++++++++++--------- src/video/x11/SDL_x11modes.c | 7 +++++-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/video/fbcon/SDL_fbevents.c b/src/video/fbcon/SDL_fbevents.c index b3d56d0ea..eaec74451 100644 --- a/src/video/fbcon/SDL_fbevents.c +++ b/src/video/fbcon/SDL_fbevents.c @@ -359,9 +359,10 @@ static int find_pid(DIR *proc, const char *wanted_name) 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 @@ static int set_imps2_mode(int fd) 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 @@ static int detect_imps2(int fd) 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 @@ static void handle_mouse(_THIS) /* 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 @@ static void handle_mouse(_THIS) 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 ) { diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index c78269947..84869131a 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -465,10 +465,13 @@ static int CheckVidMode(_THIS, int *major, int *minor) 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;