/** Initialize decoding and reads the first value */
-void ff_bgmc_decode_init(GetBitContext *gb, unsigned int *h,
+int ff_bgmc_decode_init(GetBitContext *gb, unsigned int *h,
unsigned int *l, unsigned int *v)
{
+ if (get_bits_left(gb) < VALUE_BITS)
+ return AVERROR_INVALIDDATA;
+
*h = TOP_VALUE;
*l = 0;
- *v = get_bits_long(gb, VALUE_BITS);
+ *v = get_bits(gb, VALUE_BITS);
+
+ return 0;
}