From: Jarkko Hietaniemi Date: Mon, 7 Jul 2003 09:06:58 +0000 (+0000) Subject: PerlIO_read() can return negative. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=adac3afb577bf8dbdb46781b295def44cdc58b93;p=p5sagit%2Fp5-mst-13.2.git PerlIO_read() can return negative. p4raw-id: //depot/perl@20048 --- diff --git a/ext/Digest/MD5/MD5.xs b/ext/Digest/MD5/MD5.xs index 0bf05f0..5c90f22 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); }