[Tarantool-patches] [PATCH 14/14] popen: fix popen_write_timeout retval type

Alexander Turenko alexander.turenko at tarantool.org
Wed Apr 15 07:52:55 MSK 2020


On Linux x86_64 `ssize_t` is 64 bit, while `int` is 32 bit wide (at
least typically). Let's return `ssize_t` from popen_write_timeout() to
prevent data loss.

Part of #4031

Reported-by: Cyrill Gorcunov <gorcunov at gmail.com>
Acked-by: Cyrill Gorcunov <gorcunov at gmail.com>
---
 src/lib/core/popen.c | 6 +++---
 src/lib/core/popen.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/lib/core/popen.c b/src/lib/core/popen.c
index cbf2fd690..bb55a80e7 100644
--- a/src/lib/core/popen.c
+++ b/src/lib/core/popen.c
@@ -370,7 +370,7 @@ stdX_str(unsigned int index)
  * FIXME: Provide an info re amount written bytes in the case.
  *        Say, return -(written) in the case.
  */
-int
+ssize_t
 popen_write_timeout(struct popen_handle *handle, const void *buf,
 		    size_t count, unsigned int flags,
 		    ev_tstamp timeout)
@@ -397,8 +397,8 @@ popen_write_timeout(struct popen_handle *handle, const void *buf,
 		  handle->pid, stdX_str(idx), idx, buf, count,
 		  handle->ios[idx].fd, timeout);
 
-	int rc = coio_write_timeout_noxc(&handle->ios[idx], buf, count,
-					 timeout);
+	ssize_t rc = coio_write_timeout_noxc(&handle->ios[idx], buf,
+					     count, timeout);
 	assert(rc < 0 || rc == (ssize_t)count);
 	return rc;
 }
diff --git a/src/lib/core/popen.h b/src/lib/core/popen.h
index cffb53933..4f4a6d99d 100644
--- a/src/lib/core/popen.h
+++ b/src/lib/core/popen.h
@@ -167,7 +167,7 @@ popen_stat(struct popen_handle *handle, struct popen_stat *st);
 extern const char *
 popen_command(struct popen_handle *handle);
 
-extern int
+extern ssize_t
 popen_write_timeout(struct popen_handle *handle, const void *buf,
 		    size_t count, unsigned int flags,
 		    ev_tstamp timeout);
-- 
2.25.0



More information about the Tarantool-patches mailing list