[njs] Fixing Coverity warnings related to close().

Dmitry Volyntsev xeioex at nginx.com
Mon Nov 20 16:25:31 UTC 2017


details:   http://hg.nginx.org/njs/rev/e51a848edba3
branches:  
changeset: 429:e51a848edba3
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Mon Nov 20 19:24:56 2017 +0300
description:
Fixing Coverity warnings related to close().

Coverity assumes that open() can normally return 0.

diffstat:

 njs/njs_fs.c |  24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)

diffs (69 lines):

diff -r 7ada5170b7bb -r e51a848edba3 njs/njs_fs.c
--- a/njs/njs_fs.c	Mon Nov 20 19:24:56 2017 +0300
+++ b/njs/njs_fs.c	Mon Nov 20 19:24:56 2017 +0300
@@ -277,8 +277,8 @@ njs_fs_read_file(njs_vm_t *vm, njs_value
 
 done:
 
-    if (fd > 0) {
-        close(fd);
+    if (fd != -1) {
+        (void) close(fd);
     }
 
     if (description != 0) {
@@ -305,8 +305,8 @@ done:
 
 memory_error:
 
-    if (fd > 0) {
-        close(fd);
+    if (fd != -1) {
+        (void) close(fd);
     }
 
     njs_exception_memory_error(vm);
@@ -476,8 +476,8 @@ njs_fs_read_file_sync(njs_vm_t *vm, njs_
 
 done:
 
-    if (fd > 0) {
-        close(fd);
+    if (fd != -1) {
+        (void) close(fd);
     }
 
     if (description != 0) {
@@ -491,8 +491,8 @@ done:
 
 memory_error:
 
-    if (fd > 0) {
-        close(fd);
+    if (fd != -1) {
+        (void) close(fd);
     }
 
     njs_exception_memory_error(vm);
@@ -696,8 +696,8 @@ static njs_ret_t njs_fs_write_file_inter
 
 done:
 
-    if (fd > 0) {
-        close(fd);
+    if (fd != -1) {
+        (void) close(fd);
     }
 
     if (description != 0) {
@@ -868,8 +868,8 @@ njs_fs_write_file_sync_internal(njs_vm_t
 
 done:
 
-    if (fd > 0) {
-        close(fd);
+    if (fd != -1) {
+        (void) close(fd);
     }
 
     if (description != 0) {


More information about the nginx-devel mailing list