From ca088f5fc116542c7e19136eb3546b71200af612 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 68d30e088c..99b896998f 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 baf4313170..58c8144ac6 100644 --- a/test/lisp/emacs-lisp/bindat-tests.el +++ b/test/lisp/emacs-lisp/bindat-tests.el @@ -194,7 +194,6 @@ bindat-test--recursive (should (equal (bindat-pack spec "abc") "abc\0"))) (ert-deftest bindat-test--strz-varlen-unpack () - :expected-result :failed ;; There is no test for unpacking a string without a null ;; terminator because such packed strings cannot be produced from ;; the spec (packing "a" should produce "a\0", not "a"). -- 2.36.1