From: Nicholas Clark Date: Sat, 15 Apr 2006 21:50:12 +0000 (+0000) Subject: Coverity was getting upset about an assignment from a function X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7d78471c63f10d04f55bbf9f835712005c358e03;p=p5sagit%2Fp5-mst-13.2.git Coverity was getting upset about an assignment from a function returning int to a U8 variable. Curiously it was only getting upset about the first of many. However, we are doing NO ERROR CHECKING on whether we read in the requested number of bytes of bytecode. All except BGET_op_tr_array will now croak on a short read. p4raw-id: //depot/perl@27826 --- diff --git a/ext/ByteLoader/bytecode.h b/ext/ByteLoader/bytecode.h index 3e6f9d9..0dceac4 100644 --- a/ext/ByteLoader/bytecode.h +++ b/ext/ByteLoader/bytecode.h @@ -13,20 +13,29 @@ typedef char *pvindex; /* all this should be made endianness-agnostic */ -#define BGET_U8(arg) arg = BGET_FGETC() -#define BGET_U16(arg) \ - BGET_FREAD(&arg, sizeof(U16), 1) -#define BGET_U32(arg) \ - BGET_FREAD(&arg, sizeof(U32), 1) -#define BGET_UV(arg) \ - BGET_FREAD(&arg, sizeof(UV), 1) -#define BGET_PADOFFSET(arg) \ - BGET_FREAD(&arg, sizeof(PADOFFSET), 1) -#define BGET_long(arg) \ - BGET_FREAD(&arg, sizeof(long), 1) - -#define BGET_I32(arg) BGET_U32(arg) -#define BGET_IV(arg) BGET_UV(arg) +#define BGET_U8(arg) STMT_START { \ + const int _arg = BGET_FGETC(); \ + if (_arg < 0) { \ + Perl_croak(aTHX_ \ + "EOF or error while trying to read 1 byte for U8"); \ + } \ + arg = (U8) _arg; \ + } STMT_END + +#define BGET_U16(arg) BGET_OR_CROAK(arg, U16) +#define BGET_I32(arg) BGET_OR_CROAK(arg, U32) +#define BGET_U32(arg) BGET_OR_CROAK(arg, U32) +#define BGET_IV(arg) BGET_OR_CROAK(arg, UV) +#define BGET_PADOFFSET(arg) BGET_OR_CROAK(arg, UV) +#define BGET_long(arg) BGET_OR_CROAK(arg, long) + +#define BGET_OR_CROAK(arg, type) STMT_START { \ + if (BGET_FREAD(&arg, sizeof(type), 1) < 1) { \ + Perl_croak(aTHX_ \ + "EOF or error while trying to read %d bytes for %s", \ + sizeof(type), STRINGIFY(type)); \ + } \ + } STMT_END #define BGET_PV(arg) STMT_START { \ BGET_U32(arg); \