Patchwork [PATCHv1,4/5] tests: jittertest: fix set of compiler warnings

login
register
mail settings
Submitter Shevchenko Andriy (EXT-Teleca/Helsinki)
Date April 5, 2011, 1:55 p.m.
Message ID <741f4ff14ea8ad70001e78a94e98e01dbe783b3b.1302011698.git.ext-andriy.shevchenko@nokia.com>
Download mbox | patch
Permalink /patch/89866/
State New
Headers show

Comments

Shevchenko Andriy (EXT-Teleca/Helsinki) - April 5, 2011, 1:55 p.m.
- time() was used without prototype.
- the return value of read() and write() wasn't checked
- classificator in printf() was wrong for argument of size_t type

Signed-off-by: Andy Shevchenko <ext-andriy.shevchenko@nokia.com>
---
 tests/jittertest/JitterTest.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
Artem Bityutskiy - April 5, 2011, 2:20 p.m.
On Tue, 2011-04-05 at 16:55 +0300, Andy Shevchenko wrote:
> -        write(fdSnapshot, readBuf, readBytes);
> +       int writeBytes = write(fdSnapshot, readBuf, readBytes);
> +       if (writeBytes < 0)
> +               perror("write error"); 

Then you should better check for (writeBytes != readBytes). Similar to
the read case you fix in this patch.

Patch

diff --git a/tests/jittertest/JitterTest.c b/tests/jittertest/JitterTest.c
index fcf8e0d..11dc8f5 100644
--- a/tests/jittertest/JitterTest.c
+++ b/tests/jittertest/JitterTest.c
@@ -82,6 +82,7 @@ 
 #include <string.h>     /* strcpy, strcmp */
 #include <stdlib.h>     /* exit, atol, atoi */
 #include <sys/time.h>   /* setitimer, settimeofday, gettimeofday */
+#include <time.h>	/* time */
 #include <signal.h>     /* signal */
 #include <sched.h>      /* sched_setscheduler, sched_get_priority_min,*/
 /*   sched_get_priority_max */
@@ -475,7 +476,9 @@  void doGrabKProfile(int jitterusec, char *fileName)
 
     while((readBytes = read(fdProfile, readBuf, sizeof(readBuf))) > 0)
     {
-        write(fdSnapshot, readBuf, readBytes);
+	int writeBytes = write(fdSnapshot, readBuf, readBytes);
+	if (writeBytes < 0)
+		perror("write error");
     }
 
     close(fdSnapshot);
@@ -650,7 +653,9 @@  void AlarmHandler(
         if(DoRead)
         {
 
-            read(Fd2, tmpBuf, 1);
+	    cntr = read(Fd2, tmpBuf, 1);
+	    if (cntr < 0)
+		perror("read error");
             lseek(Fd2, 0, SEEK_SET); /* back to start */
         }
 
@@ -1032,7 +1037,7 @@  int Write(int fd, void *buf, size_t bytes, int lineNo)
     if(err < bytes)
     {
 
-        printf("Write Error at line %i! Wanted to write %i bytes, but wrote only %i bytes.\n",
+        printf("Write Error at line %i! Wanted to write %zu bytes, but wrote only %i bytes.\n",
                lineNo, bytes, err);
         perror("Write did not complete. Error. Bye:"); /* show error from errno. */
 	exit(1);