@@ -1563,24 +1563,34 @@ def self.load_codepage()
15631563 @@codepage_map_cache = map
15641564 end
15651565
1566+ # @param str [String] Data to checksum
1567+ # @return [Fixnum] 8-bit checksum
15661568 def self . checksum8 ( str )
1567- str . unpack ( "C*" ) . inject ( :+ ) % 0x100
1569+ ( str . unpack ( "C*" ) . inject ( :+ ) || 0 ) % 0x100
15681570 end
15691571
1572+ # @param str [String] Little-endian data to checksum
1573+ # @return [Fixnum] 16-bit checksum
15701574 def self . checksum16_le ( str )
1571- str . unpack ( "v*" ) . inject ( :+ ) % 0x10000
1575+ ( str . unpack ( "v*" ) . inject ( :+ ) || 0 ) % 0x10000
15721576 end
15731577
1578+ # @param str [String] Big-endian data to checksum
1579+ # @return [Fixnum] 16-bit checksum
15741580 def self . checksum16_be ( str )
1575- str . unpack ( "n*" ) . inject ( :+ ) % 0x10000
1581+ ( str . unpack ( "n*" ) . inject ( :+ ) || 0 ) % 0x10000
15761582 end
15771583
1584+ # @param str [String] Little-endian data to checksum
1585+ # @return [Fixnum] 32-bit checksum
15781586 def self . checksum32_le ( str )
1579- str . unpack ( "V*" ) . inject ( :+ ) % 0x100000000
1587+ ( str . unpack ( "V*" ) . inject ( :+ ) || 0 ) % 0x100000000
15801588 end
15811589
1590+ # @param str [String] Big-endian data to checksum
1591+ # @return [Fixnum] 32-bit checksum
15821592 def self . checksum32_be ( str )
1583- str . unpack ( "N*" ) . inject ( :+ ) % 0x100000000
1593+ ( str . unpack ( "N*" ) . inject ( :+ ) || 0 ) % 0x100000000
15841594 end
15851595
15861596end
0 commit comments