Fix empty array refers; ref #4556

For example, `"".unpack("")` evaluates to `[]`.
This commit is contained in:
dearblue
2019-07-15 11:23:50 +09:00
parent 4861be1171
commit fd89948164
+6 -1
View File
@@ -1299,7 +1299,12 @@ pack_unpack(mrb_state *mrb, mrb_value str, int single)
if (single) break;
}
if (single) return RARRAY_PTR(result)[0];
if (single) {
if (RARRAY_LEN(result) > 0) {
return RARRAY_PTR(result)[0];
}
return mrb_nil_value();
}
return result;
}