From adac3afb577bf8dbdb46781b295def44cdc58b93 Mon Sep 17 00:00:00 2001 From: Jarkko Hietaniemi Date: Mon, 7 Jul 2003 09:06:58 +0000 Subject: PerlIO_read() can return negative. p4raw-id: //depot/perl@20048 --- ext/Digest/MD5/MD5.xs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ext/Digest/MD5/MD5.xs b/ext/Digest/MD5/MD5.xs index 0bf05f0c57..5c90f2238d 100644 --- a/ext/Digest/MD5/MD5.xs +++ b/ext/Digest/MD5/MD5.xs @@ -621,7 +621,7 @@ addfile(self, fh) MD5_CTX* context = get_md5_ctx(self); STRLEN fill = context->bytes_low & 0x3F; unsigned char buffer[4096]; - int n; + SSize_t n; CODE: if (fh) { if (fill) { @@ -630,14 +630,19 @@ addfile(self, fh) * first. */ STRLEN missing = 64 - fill; - if ( (n = PerlIO_read(fh, buffer, missing))) + n = PerlIO_read(fh, buffer, missing); + if (n >= 0) MD5Update(context, buffer, n); - else + else { + if (PerlIO_error(fh)) { + croak("Reading from filehandle failed"); + } XSRETURN(1); /* self */ + } } /* Process blocks until EOF or error */ - while ( (n = PerlIO_read(fh, buffer, sizeof(buffer)))) { + while ( (n = PerlIO_read(fh, buffer, sizeof(buffer))) > 0 ) { MD5Update(context, buffer, n); } -- cgit v1.2.1