The bitmap offset is a signed 32bit number, so casting to (long) isn't sufficient. We must cast to (int32_t).