bindat (strz): Fix off-by-one bug in computed length
* lisp/emacs-lisp/bindat.el (strz): Include null terminator when computing packed string length. * test/lisp/emacs-lisp/bindat-tests.el (strz): Mark tests as passing.
This commit is contained in:
parent
916492cb6d
commit
e66d6b3793
2 changed files with 2 additions and 4 deletions
|
@ -688,9 +688,9 @@ is the name of a variable that will hold the value we need to pack.")
|
|||
('unpack `(bindat--unpack-strz ,len))
|
||||
(`(length ,val)
|
||||
`(cl-incf bindat-idx ,(cond
|
||||
((null len) `(length ,val))
|
||||
((null len) `(1+ (length ,val)))
|
||||
((numberp len) len)
|
||||
(t `(or ,len (length ,val))))))
|
||||
(t `(or ,len (1+ (length ,val)))))))
|
||||
(`(pack . ,args)
|
||||
(macroexp-let2 nil len len
|
||||
`(if ,len
|
||||
|
|
|
@ -191,12 +191,10 @@
|
|||
|
||||
(let ((spec (bindat-type strz)))
|
||||
(ert-deftest bindat-test--strz-varlen-len ()
|
||||
:expected-result :failed
|
||||
(should (equal (bindat-length spec "") 1))
|
||||
(should (equal (bindat-length spec "abc") 4)))
|
||||
|
||||
(ert-deftest bindat-test--strz-varlen-pack ()
|
||||
:expected-result :failed
|
||||
(should (equal (bindat-pack spec "") "\0"))
|
||||
(should (equal (bindat-pack spec "abc") "abc\0")))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue