summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2003-07-07 09:06:58 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2003-07-07 09:06:58 +0000
commitadac3afb577bf8dbdb46781b295def44cdc58b93 (patch)
treea5aa4b256882a9e7d35e5234dbed5bed75f0c438
parent5d899d7e93cbefd07b08ec237620bc02ce3e1e1c (diff)
downloadperl-adac3afb577bf8dbdb46781b295def44cdc58b93.tar.gz
PerlIO_read() can return negative.
p4raw-id: //depot/perl@20048
-rw-r--r--ext/Digest/MD5/MD5.xs13
1 files 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);
}