From fbacc1e2472fdb1d898e10a227fac91962464cf8 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Tue, 16 Feb 2021 17:24:38 +0100 Subject: low: make-cstr-array: Simplify and fix off-by-one error. --- drmaa/v1/low.scm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drmaa/v1/low.scm b/drmaa/v1/low.scm index 97e9a67..52d37f3 100644 --- a/drmaa/v1/low.scm +++ b/drmaa/v1/low.scm @@ -85,15 +85,15 @@ STRING-LIST." (let* ((n (length string-list)) (pointers (map string->pointer string-list)) (addresses (map pointer-address pointers)) - (bv (make-bytevector (* (1+ n) (sizeof '*)))) + ;; Make it one item longer, because it needs to be a + ;; NULL-terminated array. + (bv (make-bytevector (* (1+ n) (sizeof '*)) 0)) (bv-set! (case (sizeof '*) ((4) bytevector-u32-native-set!) ((8) bytevector-u64-native-set!)))) (for-each (lambda (address index) (bv-set! bv (* (sizeof '*) index) address)) addresses (iota n)) - ;; The vector must be NULL-terminated - (bv-set! bv (* (1+ n) (sizeof '*)) 0) bv)) (define-syntax-rule (return ret success error-message) -- cgit v1.2.3