From 6a57f4b3bb71cc1ea11eaa11b9e4cf14d37a08b7 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 9 Jun 2022 19:58:56 -0400 Subject: [PATCH 1/4] bindat (strz): Fix documentation for strz with pre-allocated string * doc/lispref/processes.texi (Bindat Types): Document that a null terminator is not written if `bindat-pack' is given a pre-allocated string. --- doc/lispref/processes.texi | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index 7c37853eca..55fb93ec5a 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi @@ -3490,12 +3490,21 @@ Bindat Types @item strz &optional @var{len} If @var{len} is not provided: Variable-length null-terminated unibyte string (@pxref{Text Representations}). When packing, the entire input -string is copied to the packed output followed by a null byte. The +string is copied to the packed output. The following byte will be +null (zero) unless a pre-allocated string was provided to +@code{bindat-pack}, in which case that byte is left unmodified. The length of the packed output is the length of the input string plus one -(for the added null byte). The input string must not contain any null +(for the null terminator). The input string must not contain any null bytes. When unpacking, the resulting string contains all bytes up to (but excluding) the null byte. +@quotation Caution +If a pre-allocated string is provided to @code{bindat-pack}, the +packed output will not be properly null-terminated unless the +pre-allocated string already has a null byte at the appropriate +location. +@end quotation + If @var{len} is provided: @code{strz} behaves the same as @code{str} with one difference: When unpacking, the first null byte encountered in the packed string and all subsequent bytes are excluded from the -- 2.36.1