summaryrefslogtreecommitdiffstats
path: root/crypto/bio
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2009-03-07 16:58:43 +0000
committerDr. Stephen Henson <steve@openssl.org>2009-03-07 16:58:43 +0000
commit4fcf8d8b074590475128f2debec5278f585837a0 (patch)
treed4156e4d7e1899847a88f02839af5cff26305a09 /crypto/bio
parentb7650eb21ed3af765bf7d4707c4873282e303216 (diff)
Submitted by: Jeremy Shapiro <jnshapir@us.ibm.com>
Reviewed by: steve@openssl.org Improve efficientcy of mem_gets().
Diffstat (limited to 'crypto/bio')
-rw-r--r--crypto/bio/bss_mem.c22
1 files changed, 12 insertions, 10 deletions
diff --git a/crypto/bio/bss_mem.c b/crypto/bio/bss_mem.c
index a4edb711ae..e7ab9cb3a3 100644
--- a/crypto/bio/bss_mem.c
+++ b/crypto/bio/bss_mem.c
@@ -284,6 +284,7 @@ static int mem_gets(BIO *bp, char *buf, int size)
BIO_clear_retry_flags(bp);
j=bm->length;
+ if ((size-1) < j) j=size-1;
if (j <= 0)
{
*buf='\0';
@@ -292,17 +293,18 @@ static int mem_gets(BIO *bp, char *buf, int size)
p=bm->data;
for (i=0; i<j; i++)
{
- if (p[i] == '\n') break;
- }
- if (i == j)
- {
- BIO_set_retry_read(bp);
- /* return(-1); change the semantics 0.6.6a */
+ if (p[i] == '\n')
+ {
+ i++;
+ break;
+ }
}
- else
- i++;
- /* i is the max to copy */
- if ((size-1) < i) i=size-1;
+
+ /*
+ * i is now the max num of bytes to copy, either j or up to
+ * and including the first newline
+ */
+
i=mem_read(bp,buf,i);
if (i > 0) buf[i]='\0';
ret=i;