summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Clark <nick@ccl4.org>2006-04-15 21:50:12 +0000
committerNicholas Clark <nick@ccl4.org>2006-04-15 21:50:12 +0000
commit7d78471c63f10d04f55bbf9f835712005c358e03 (patch)
tree663820ce04bd60b32a53e2543682a44da7609ede
parent0d3260984663aa39a4c25834f566132d81a03c27 (diff)
downloadperl-7d78471c63f10d04f55bbf9f835712005c358e03.tar.gz
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
-rw-r--r--ext/ByteLoader/bytecode.h37
1 files changed, 23 insertions, 14 deletions
diff --git a/ext/ByteLoader/bytecode.h b/ext/ByteLoader/bytecode.h
index 3e6f9d9e33..0dceac4324 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); \