aboutsummaryrefslogtreecommitdiff
path: root/testes
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-06-21 14:55:12 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-06-21 14:55:12 -0300
commitec65ab878e04822f1cbcc3198f19076d57900e9f (patch)
tree936dd02a1e6c6eed833ccedaee2f7b1b3fc7e697 /testes
parente24ce8c2b322226bbc211e57f301c265a2622c4b (diff)
downloadlua-ec65ab878e04822f1cbcc3198f19076d57900e9f.tar.gz
lua-ec65ab878e04822f1cbcc3198f19076d57900e9f.tar.bz2
lua-ec65ab878e04822f1cbcc3198f19076d57900e9f.zip
Removed 'int' size limit for pack/unpack
Diffstat (limited to 'testes')
-rw-r--r--testes/tpack.lua19
1 files changed, 10 insertions, 9 deletions
diff --git a/testes/tpack.lua b/testes/tpack.lua
index bfa63fc4..4b32efb5 100644
--- a/testes/tpack.lua
+++ b/testes/tpack.lua
@@ -135,15 +135,15 @@ checkerror("variable%-length format", packsize, "z")
135-- overflow in option size (error will be in digit after limit) 135-- overflow in option size (error will be in digit after limit)
136checkerror("invalid format", packsize, "c1" .. string.rep("0", 40)) 136checkerror("invalid format", packsize, "c1" .. string.rep("0", 40))
137 137
138if packsize("i") == 4 then 138do
139 -- result would be 2^31 (2^3 repetitions of 2^28 strings) 139 local maxsize = (packsize("j") <= packsize("T")) and
140 local s = string.rep("c268435456", 2^3) 140 math.maxinteger or (1 << (packsize("T") * 8))
141 checkerror("too large", packsize, s) 141 assert (packsize(string.format("c%d", maxsize - 9)) == maxsize - 9)
142 -- one less is OK 142 checkerror("too large", packsize, string.format("c%dc10", maxsize - 9))
143 s = string.rep("c268435456", 2^3 - 1) .. "c268435455" 143 checkerror("too long", pack, string.format("xxxxxxxxxx c%d", maxsize - 9))
144 assert(packsize(s) == 0x7fffffff)
145end 144end
146 145
146
147-- overflow in packing 147-- overflow in packing
148for i = 1, sizeLI - 1 do 148for i = 1, sizeLI - 1 do
149 local umax = (1 << (i * 8)) - 1 149 local umax = (1 << (i * 8)) - 1
@@ -229,8 +229,9 @@ do
229 assert(pack("c3", "123") == "123") 229 assert(pack("c3", "123") == "123")
230 assert(pack("c0", "") == "") 230 assert(pack("c0", "") == "")
231 assert(pack("c8", "123456") == "123456\0\0") 231 assert(pack("c8", "123456") == "123456\0\0")
232 assert(pack("c88", "") == string.rep("\0", 88)) 232 assert(pack("c88 c1", "", "X") == string.rep("\0", 88) .. "X")
233 assert(pack("c188", "ab") == "ab" .. string.rep("\0", 188 - 2)) 233 assert(pack("c188 c2", "ab", "X\1") ==
234 "ab" .. string.rep("\0", 188 - 2) .. "X\1")
234 local a, b, c = unpack("!4 z c3", "abcdefghi\0xyz") 235 local a, b, c = unpack("!4 z c3", "abcdefghi\0xyz")
235 assert(a == "abcdefghi" and b == "xyz" and c == 14) 236 assert(a == "abcdefghi" and b == "xyz" and c == 14)
236 checkerror("longer than", pack, "c3", "1234") 237 checkerror("longer than", pack, "c3", "1234")