summaryrefslogtreecommitdiff
path: root/src/rio.c
diff options
context:
space:
mode:
authorEwg-c <88107289+Ewg-c@users.noreply.github.com>2021-07-29 17:29:23 -0700
committerGitHub <noreply@github.com>2021-07-29 17:29:23 -0700
commita40381640502439f751f42c4b23d4c6d396993e3 (patch)
tree5b1f5e52b45a27400127c2681cd3983f35dd6ada /src/rio.c
parent8bf433dc86937a72cbcfa02743a093c2e3d91960 (diff)
downloadredis-a40381640502439f751f42c4b23d4c6d396993e3.tar.gz
Minor refactoring for rioConnRead and adding errno (#9280)
minor refactoring for rioConnRead and adding errno
Diffstat (limited to 'src/rio.c')
-rw-r--r--src/rio.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/src/rio.c b/src/rio.c
index 529f0aeb9..2234ec6e3 100644
--- a/src/rio.c
+++ b/src/rio.c
@@ -187,6 +187,14 @@ static size_t rioConnRead(rio *r, void *buf, size_t len) {
r->io.conn.pos = 0;
}
+ /* Make sure the caller didn't request to read past the limit.
+ * If they didn't we'll buffer till the limit, if they did, we'll
+ * return an error. */
+ if (r->io.conn.read_limit != 0 && r->io.conn.read_limit < r->io.conn.read_so_far + len) {
+ errno = EOVERFLOW;
+ return 0;
+ }
+
/* If we don't already have all the data in the sds, read more */
while (len > sdslen(r->io.conn.buf) - r->io.conn.pos) {
size_t buffered = sdslen(r->io.conn.buf) - r->io.conn.pos;
@@ -198,15 +206,7 @@ static size_t rioConnRead(rio *r, void *buf, size_t len) {
if (r->io.conn.read_limit != 0 &&
r->io.conn.read_so_far + buffered + toread > r->io.conn.read_limit)
{
- /* Make sure the caller didn't request to read past the limit.
- * If they didn't we'll buffer till the limit, if they did, we'll
- * return an error. */
- if (r->io.conn.read_limit >= r->io.conn.read_so_far + len)
- toread = r->io.conn.read_limit - r->io.conn.read_so_far - buffered;
- else {
- errno = EOVERFLOW;
- return 0;
- }
+ toread = r->io.conn.read_limit - r->io.conn.read_so_far - buffered;
}
int retval = connRead(r->io.conn.conn,
(char*)r->io.conn.buf + sdslen(r->io.conn.buf),