summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLi Xiaoming <lixm.fnst@cn.fujitsu.com>2019-08-26 21:29:31 +0800
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2019-08-28 14:51:50 +0000
commit392cad1a8dbfda836abf7f545e8ad46e100266e7 (patch)
treea9fbb227c7a0dea7278955d6887210d41d7e8f93
parentb9b14dda5ed0e06c4b6e59512b1289ba81a4e765 (diff)
tsrecorder.c:Fix return value check of read()
If read() fails, it returns -1. It will generate unpredictable result when compare -1 and sizeof()'s size_t(unsigned) value. By the way, cast “ssize_t” to “size_t” to slience the warning. Bug-AGL:SPEC-2422 Change-Id: Ib56c1ebbcaaac48600a6747d5cc013c407dc14dd Signed-off-by: Li Xiaoming <lixm.fnst@cn.fujitsu.com> (cherry picked from commit ee6c0cc56304467061f9a60f3f96d07d741f327f)
-rw-r--r--tsutils/tsrecorder/tsrecorder.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/tsutils/tsrecorder/tsrecorder.c b/tsutils/tsrecorder/tsrecorder.c
index 9c2e466..82beccb 100644
--- a/tsutils/tsrecorder/tsrecorder.c
+++ b/tsutils/tsrecorder/tsrecorder.c
@@ -32,16 +32,20 @@ extern char* getTouchScreenInfo();
static int handle_event()
{
- int i, rd;
+ size_t i;
+ ssize_t rd;
char str[256];
float x = 0, y = 0;
rd = read(eventFd, ev0, sizeof(struct input_event)* 64);
- if(rd < sizeof(struct input_event))
+ if(rd < 0)
+ return -1;
+
+ if((size_t)rd < sizeof(struct input_event))
return 0;
- for(i=0;i<rd/sizeof(struct input_event); i++)
+ for(i = 0; i < ((size_t)rd) / sizeof(struct input_event); i++)
{
memset(str, 0, sizeof(str));