[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 5255fa452f 4/5: bindat (strz): Fix wrong-type-argument error when
From: |
Stefan Monnier |
Subject: |
master 5255fa452f 4/5: bindat (strz): Fix wrong-type-argument error when unpacking |
Date: |
Wed, 1 Jun 2022 22:34:11 -0400 (EDT) |
branch: master
commit 5255fa452f338c2ae97fa1ade70b396513bc6e9b
Author: Richard Hansen <rhansen@rhansen.org>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
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 e597dd6247..0725b677cf 100644
--- a/lisp/emacs-lisp/bindat.el
+++ b/lisp/emacs-lisp/bindat.el
@@ -165,12 +165,12 @@
(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 cb7b6fe1c2..b3850f14f1 100644
--- a/test/lisp/emacs-lisp/bindat-tests.el
+++ b/test/lisp/emacs-lisp/bindat-tests.el
@@ -199,7 +199,6 @@
(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").