dearblue
6c2f570d79
Fixed base64 decoding in mruby-pack
...
Previously `\x80` was incorrectly mapped to `0`.
```ruby
"\x80\x80\x80\x80".unpack("m*")
# before => "\x00\x00\x00"
# after => ""
```
The reason is that the C string terminator is placed in `base64_dec_tab[128]` and the array length is obtained by `sizeof`.
Therefore, the length of `base64_dec_tab[]` is strictly specified and replaced with element-by-element initialization.
Also, similar changes are made to `base64chars[]`.
2024-04-20 09:56:08 +09:00
Yukihiro "Matz" Matsumoto
87b358a342
Including header files in include/* by <>
2024-03-26 13:59:59 +09:00
Yukihiro "Matz" Matsumoto
0fe95d6c81
mruby-pack (mrb_pack_pack): avoid integer overflow
...
`int` (32bit integer) may be too small on 64bit platforms.
2024-02-05 21:28:11 +09:00
Yukihiro "Matz" Matsumoto
39f48d732a
mruby-pack: update README.md
...
'X' and '@' directives are not listed
2023-12-30 16:02:20 +09:00
Yukihiro "Matz" Matsumoto
56b67f8613
mruby-pack (u64tostr): reimplement the function
...
- direct conversion of single digit numbers
- remove unnecessary update of `line` variable
- simplify the body according to the assertion
2023-12-30 15:35:55 +09:00
Yukihiro "Matz" Matsumoto
8cbd4638f4
mruby-pack (u64tostr): len should always be positive
...
Add `mrb_assert()` instead of just skipping the function.
2023-12-30 15:33:57 +09:00
Yukihiro "Matz" Matsumoto
1871ff14db
mruby-pack (pack_unpack): skip continuous extraction from unpack1
...
Ref #6134
2023-12-30 15:31:44 +09:00
Yukihiro "Matz" Matsumoto
7765c23f69
mruby-pack (pack_hex): the scope of variables a and b can be reduced
2023-12-30 15:12:17 +09:00
Yukihiro "Matz" Matsumoto
fca2bbdcca
mruby-pack (unpack_str): the scope of the variable cp can be reduced
2023-12-30 15:12:10 +09:00
Yukihiro "Matz" Matsumoto
159687bef3
mruby-pack: add tests for unpack1 method; ref #6134
2023-12-29 15:05:16 +09:00
Yukihiro "Matz" Matsumoto
6d8323f3c7
mruby-pack (pack_unpack): unpack1 did not return single data; fix #6134
...
For following unpack directives:
- PACK_DIR_HEX (h)
- PACK_DIR_BSTR (b)
- PACK_DIR_STR (a,A,Z)
- PACK_DIR_BASE64 (m)
- PACK_DIR_QENC (M)
2023-12-29 13:09:14 +09:00
Yukihiro "Matz" Matsumoto
097681b4d4
mruby-pack: unpack "b/B" should limit result size
2023-10-09 22:39:44 +09:00
Yukihiro "Matz" Matsumoto
393aaada64
mruby-pack/pack.c (read_tmpl): fix out-of-bound access with templates
2023-09-20 09:51:22 +09:00
Yukihiro "Matz" Matsumoto
1e1184f62d
mruby-pack/pack.c (read_tmpl): should consume skips in the function
2023-07-28 17:05:49 +09:00
Yukihiro "Matz" Matsumoto
1535e031df
mruby-pack/pack.c (read_tmpl): direct return from skipping directives
...
We used to read counts after spaces, for example `pack("j 4")` read `4`
as counts after a space.
2023-07-24 18:03:39 +09:00
Yukihiro "Matz" Matsumoto
a5a13ad35f
mruby-pack/pack.c (read_tmpl): read_tmpl to return dir
...
Use return value for directives information.
2023-07-24 18:03:39 +09:00
Yukihiro "Matz" Matsumoto
8a3d52f494
mruby-pack/pack.c (read_tmpl): rename PACK_DIR_INVALID
...
The value is used for spaces and comments, so the term "skip" is more
appropriate than "invalid".
2023-07-24 18:03:38 +09:00
Yukihiro "Matz" Matsumoto
e17f3256c6
mruby-pack/pack.c (read_tmpl): support comments in derectives
2023-07-24 18:03:38 +09:00
Yukihiro "Matz" Matsumoto
0eceadd037
mruby-pack/test/pack.rb: test B/b directives
2023-07-24 18:03:38 +09:00
Yukihiro "Matz" Matsumoto
e7021f190a
mruby-pack/pack.c (pack_bstr): support B/b directives
2023-07-24 18:03:38 +09:00
Yukihiro "Matz" Matsumoto
05549410d9
mruby-pack/pack.c (read_tmpl): check unknown directives
2023-07-24 18:03:38 +09:00
Yukihiro "Matz" Matsumoto
2a1e3a572c
mruby-pack/pack.c (read_tmpl): support J/j template in pack
...
J/j is available since Ruby 2.3.
2023-07-24 18:03:37 +09:00
Yukihiro "Matz" Matsumoto
ea649e70b8
mruby-pack/pack.c (mrb_pack_pack): use direct array buffer access
...
We don't need index wrap-around not boundary check here, so we can use
faster direct array access.
2023-06-29 22:54:58 +09:00
Yukihiro "Matz" Matsumoto
c32f7915fb
reformat else clause indentation style
2023-05-20 00:21:01 +09:00
Yukihiro "Matz" Matsumoto
eea72ec84a
fix spaces in the type cast expressions (cosmetic changes)
2023-05-18 23:29:16 +09:00
Yukihiro "Matz" Matsumoto
9c5dc42e59
small cosmetic changes.
...
I prefer `i++` style unless absolutely necessary.
This commit is an addition to 41e4148.
2022-11-19 17:11:56 +09:00
Yukihiro "Matz" Matsumoto
9fcfd01f20
mruby-pack/pack.c (read_tmpl): check integer overflow before casting.
2022-11-10 22:21:12 +09:00
Yukihiro "Matz" Matsumoto
4a888a34bb
readfloat.c (mrb_read_float): a new function.
...
We no longer use `mrb_float_read()` that depends on `errno`.
2022-11-07 16:09:31 +09:00
Yukihiro "Matz" Matsumoto
4e9773ae3d
readint.c (mrb_int_read): new function.
...
We no longer use `mrb_read_int` which is kinda compatible with `strtol`.
2022-11-07 16:09:31 +09:00
Yukihiro "Matz" Matsumoto
5ee42ff1dd
Merge pull request #5833 from jbampton/remove-coding-utf-8-ruby
...
Remove `# coding: utf-8` from Ruby files
2022-10-27 18:11:54 +09:00
Yukihiro "Matz" Matsumoto
8a67a26104
mruby-pack/pack.c (unpack): check if the given length is positive.
...
To avoid out-of-bound array access.
2022-10-27 16:32:05 +09:00
John Bampton
44db4f18d3
Remove # coding: utf-8 from Ruby files
...
The default script encoding is Encoding::UTF-8 after v2.0.
https://ruby-doc.org/core-2.1.2/Encoding.html#class-Encoding-label-Script+encoding
2022-10-27 04:43:13 +10:00
Yukihiro "Matz" Matsumoto
4f0679bb86
pack.c (pack_unpack): small refactoring.
2022-08-31 23:29:12 +09:00
Yukihiro "Matz" Matsumoto
15e9b09bef
pack.c (hex2int): should return signed integer.
2022-08-30 18:08:05 +09:00
Yukihiro "Matz" Matsumoto
f587edd849
pack.c: need extra space for the terminal NULL.
2022-08-23 15:05:27 +09:00
Yukihiro "Matz" Matsumoto
35a5678899
mruby-pack/pack.c: make base64_dec_tab a static array of chars.
2022-08-21 19:25:16 +09:00
dearblue
9a84ef926b
Avoid adding MRUBY_ROOT/src to cc.include_paths
2022-07-02 09:56:13 +09:00
Yukihiro "Matz" Matsumoto
0f4769536b
src/numeric.c: use mrb_ensure_float_type().
...
Instead of obsolete `mrb_to_float()` or the combination of
`mrb_float_value(mrb_as_float())`.
2022-04-25 07:29:55 +09:00
Yukihiro "Matz" Matsumoto
f45ac65532
fixup! mruby-kernel-ext/kernel.c: use mrb_ensure_integer_type().
2022-04-25 07:29:21 +09:00
Yukihiro "Matz" Matsumoto
3be461077d
mruby-pack/pack.c: fix integer size mixtures.
2022-04-21 14:47:15 +09:00
Yukihiro "Matz" Matsumoto
22a98a0ba7
pack.c: unify duplicated error handling code.
2022-03-09 15:21:14 +09:00
Yukihiro "Matz" Matsumoto
278f46f971
unpack.c: check if srcidx is shorter than srclen for safety.
2022-03-04 14:19:10 +09:00
Yukihiro "Matz" Matsumoto
bc9476e7ca
unpack.c: unpack_BER() did assume the string length is not zero.
2022-03-04 14:18:20 +09:00
Yukihiro "Matz" Matsumoto
3b59c95ead
pack.c: check integer overflow in unpacking BER; fix #5611
2021-12-23 07:57:58 +09:00
Yukihiro "Matz" Matsumoto
cbfaa5e20f
object.c: rename mrb_to_int to mrb_to_integer.
...
Consistent naming: `integer` to represent integer packed in `mrb_value`
instead of `int`.
2021-09-07 14:31:56 +09:00
Yukihiro "Matz" Matsumoto
80cf293bf6
pack.c: rename pack/unpack functions for readability.
2021-08-17 13:04:11 +09:00
Yukihiro "Matz" Matsumoto
57b347088d
fixup! pack.c: reduce dispatch in pack_unpack().
2021-08-17 13:04:06 +09:00
Yukihiro "Matz" Matsumoto
4385590d31
pack.c: reduce dispatch in pack_unpack().
2021-08-17 12:52:56 +09:00
Yukihiro "Matz" Matsumoto
bfe2bd4960
pack.c: fix M packing bug.
2021-08-16 10:56:44 +09:00
Yukihiro "Matz" Matsumoto
8e5e96239c
pack.c: fixed a overwriting bug in pack_w and pack_M.
2021-08-14 14:58:09 +09:00