Skip to content

Commit 97f7bc4

Browse files
committed
Fix 2nd argument of CRC.crc32
1 parent 0f5cb4a commit 97f7bc4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

mrbgems/picoruby-crc/mrblib/crc.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module CRC
2+
end

mrbgems/picoruby-crc/src/mrubyc/crc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,20 @@ static void
88
c_crc_crc32(mrbc_vm *vm, mrbc_value v[], int argc)
99
{
1010
mrbc_value string = GET_ARG(1);
11-
mrbc_int_t crc = GET_INT_ARG(2);
11+
mrbc_int_t crc;
12+
if (argc < 2) {
13+
crc = 0;
14+
} else {
15+
crc = GET_INT_ARG(2);
16+
}
1217
if (string.tt == MRBC_TT_NIL) {
1318
SET_INT_RETURN(0);
1419
return;
1520
} else if (string.tt != MRBC_TT_STRING) {
1621
mrbc_raise(vm, MRBC_CLASS(TypeError), "string expected");
1722
return;
1823
}
19-
uint32_t crc_value = generate_crc32((uint8_t *)string.string->data, string.string->size, crc);
24+
uint32_t crc_value = generate_crc32((uint8_t *)string.string->data, (size_t)string.string->size, (uint32_t)crc);
2025
SET_INT_RETURN(crc_value);
2126
}
2227

0 commit comments

Comments
 (0)