From fa1835bd83fc8e64426023fe979079bfa21cbdcb Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sat, 28 May 2022 23:10:44 -0400 Subject: [PATCH 2/7] 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. --- lisp/emacs-lisp/bindat.el | 4 ++-- test/lisp/emacs-lisp/bindat-tests.el | 2 -- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/lisp/emacs-lisp/bindat.el b/lisp/emacs-lisp/bindat.el index c6d64975ec..b236e47e5b 100644 --- a/lisp/emacs-lisp/bindat.el +++ b/lisp/emacs-lisp/bindat.el @@ -688,9 +688,9 @@ bindat--type ('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 diff --git a/test/lisp/emacs-lisp/bindat-tests.el b/test/lisp/emacs-lisp/bindat-tests.el index fbe574e490..6added9390 100644 --- a/test/lisp/emacs-lisp/bindat-tests.el +++ b/test/lisp/emacs-lisp/bindat-tests.el @@ -187,12 +187,10 @@ bindat-test--recursive (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"))) -- 2.36.1