From 787ea356aba16bcf9dd1f41d55e3ab7e1129215c Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Sun, 29 May 2022 18:09:08 -0400 Subject: [PATCH 5/7] bindat (strz): Fix wrong-type-argument error when unpacking * lisp/emacs-lisp/bindat.el (strz): Fix (wrong-type-argument number-or-marker-p nil) error when unpacking a strz with unspecified (variable) length. * test/lisp/emacs-lisp/bindat-tests.el (strz): Mark test as passing. --- lisp/emacs-lisp/bindat.el | 4 ++-- test/lisp/emacs-lisp/bindat-tests.el | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lisp/emacs-lisp/bindat.el b/lisp/emacs-lisp/bindat.el index 12b2d20981..20095ef6cd 100644 --- a/lisp/emacs-lisp/bindat.el +++ b/lisp/emacs-lisp/bindat.el @@ -165,12 +165,12 @@ bindat--unpack-str (if (stringp s) s (apply #'unibyte-string s)))) -(defun bindat--unpack-strz (len) +(defun bindat--unpack-strz (&optional len) (let ((i 0) s) (while (and (if len (< i len) t) (/= (aref bindat-raw (+ bindat-idx i)) 0)) (setq i (1+ i))) (setq s (substring bindat-raw bindat-idx (+ bindat-idx i))) - (setq bindat-idx (+ bindat-idx len)) + (setq bindat-idx (+ bindat-idx (or len (1+ i)))) (if (stringp s) s (apply #'unibyte-string s)))) diff --git a/test/lisp/emacs-lisp/bindat-tests.el b/test/lisp/emacs-lisp/bindat-tests.el index 5152f67c01..01f9d51ad0 100644 --- a/test/lisp/emacs-lisp/bindat-tests.el +++ b/test/lisp/emacs-lisp/bindat-tests.el @@ -195,7 +195,6 @@ bindat-test--recursive (should (equal (bindat-pack spec "abc") "\141\142\143\0"))) (ert-deftest bindat-test--strz-varlen-unpack () - :expected-result :failed (should (equal (bindat-unpack spec "\0") "")) (should (equal (bindat-unpack spec "\141\142\143\0") "abc")))) -- 2.36.1