From 2f6bf52bfe71ee10a65489ea94abdaf1a90d7c8d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tommi=20H=C3=B6yn=C3=A4l=C3=A4nmaa?=
<[email protected]>
Date: Sat, 29 Nov 2025 11:21:23 +0200
Subject: [PATCH] Fixed bytevector size checks in macros write-c-struct and
read-c-struct.
The current bytevector size checks in macros write-c-struct and
read-c-struct trigger an error if the argument bytevector is larger than
needed. The correct way is to trigger an error if the bytevector is too
small.
---
module/system/foreign.scm | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/module/system/foreign.scm b/module/system/foreign.scm
index a75c37da1..4a505bdd2 100644
--- a/module/system/foreign.scm
+++ b/module/system/foreign.scm
@@ -184,7 +184,7 @@ not cross-compiling; otherwise leave it to be
evaluated at run-time."
(let ((bv %bv)
(offset %offset)
(size (compile-time-eval (sizeof (list type ...)))))
- (unless (<= (bytevector-length bv) (+ offset size))
+ (unless (>= (bytevector-length bv) (+ offset size))
(error "destination bytevector too small"))
(let*-values (((field offset)
(read-field bv offset (compile-time-eval type)))
@@ -229,7 +229,7 @@ not cross-compiling; otherwise leave it to be
evaluated at run-time."
(let ((bv %bv)
(offset %offset)
(size (compile-time-eval (sizeof (list type ...)))))
- (unless (<= (bytevector-length bv) (+ offset size))
+ (unless (>= (bytevector-length bv) (+ offset size))
(error "destination bytevector too small"))
(let* ((offset (write-field bv offset (compile-time-eval type) field))
...)
--
2.47.3
--
Kotisivu / Homepage: http://www.iki.fi/tohoyn/
Sähköposti / E-Mail: [email protected]
GPG-sormenjälki / GPG fingerprint:
55F4 2477 7155 3528 5CB2 2B7A BB86 1FDE 4046 0F83
FT, Debian-ylläpitäjä / PhD, Debian Maintainer