[05/11] xf86drm: Avoid negative array index value

Submitted by Praveen Paneri on April 10, 2015, 8:42 a.m.

Details

Message ID 1428655383-26087-6-git-send-email-praveen.paneri@intel.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Praveen Paneri April 10, 2015, 8:42 a.m.
Variable retcode can be negative as well. Put the correct
condition on it before using it as array index.

Signed-off-by: Praveen Paneri <praveen.paneri@intel.com>
---
 xf86drm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/xf86drm.c b/xf86drm.c
index ffc53b8..4af98a8 100644
--- a/xf86drm.c
+++ b/xf86drm.c
@@ -661,7 +661,7 @@  static int drmOpenByName(const char *name, int type)
 	if ((fd = open(proc_name, 0, 0)) >= 0) {
 	    retcode = read(fd, buf, sizeof(buf)-1);
 	    close(fd);
-	    if (retcode) {
+	    if (retcode > 0) {
 		buf[retcode-1] = '\0';
 		for (driver = pt = buf; *pt && *pt != ' '; ++pt)
 		    ;