浏览代码

Fix unused result on write warning

Renato Golin 13 年之前
父节点
当前提交
90cef3831f
共有 4 个文件被更改,包括 16 次插入5 次删除
  1. 5 1
      dali/dfuplus/dfuplus.cpp
  2. 2 1
      system/jlib/jsocket.cpp
  3. 4 2
      system/jlib/jstream.cpp
  4. 5 1
      tools/hidl/hidlcomp.cpp

+ 5 - 1
dali/dfuplus/dfuplus.cpp

@@ -1213,7 +1213,11 @@ int CDfuPlusHelper::savexml()
     }
     
     const MemoryBuffer& xmlmap = resp->getXmlmap();
-    write(ofile, xmlmap.toByteArray(), xmlmap.length());
+    ssize_t written = write(ofile, xmlmap.toByteArray(), xmlmap.length());
+    if (written < 0)
+        throw MakeStringException(-1, "can't write to file %s\n", dstxml);
+    if (written != xmlmap.length())
+        throw MakeStringException(-1, "truncated write to file %s\n", dstxml);
     close(ofile);
     return 0;
 }

+ 2 - 1
system/jlib/jsocket.cpp

@@ -3561,7 +3561,8 @@ class CSocketSelectThread: public Thread
 #ifdef _USE_PIPE_FOR_SELECT_TRIGGER
         CriticalBlock block(sect);
         char c = 0;
-        write(dummysock[1], &c, 1);
+        if(write(dummysock[1], &c, 1) != 1)
+            throwUnexpected();
 #else
         closedummy();
 #endif

+ 4 - 2
system/jlib/jstream.cpp

@@ -219,12 +219,14 @@ CFileOutputStream::CFileOutputStream(int _handle)
 
 void CFileOutputStream::writeByte(byte b)
 {
-    _write(handle, &b, 1);
+    if (_write(handle, &b, 1) != 1)
+        throwUnexpected();
 }
 
 void CFileOutputStream::writeBytes(const void *b, int len)
 {
-    _write(handle, b, len);
+    if (_write(handle, b, len) != len)
+        throwUnexpected();
 }
 
 extern jlib_decl IByteOutputStream *createOutputStream(int handle)

+ 5 - 1
tools/hidl/hidlcomp.cpp

@@ -283,7 +283,11 @@ void indent(int indents)
 
 void out(const char *s,size_t l)
 {
-    write(gOutfile,s,(unsigned)l);
+    ssize_t written = write(gOutfile,s,(unsigned)l);
+    if (written < 0)
+        throw "Error while writing out";
+    if (written != l)
+        throw "Truncated write";
 }
 
 void outs(const char *s)