From 089b0e54e868e0c28b262d6b09a2d6af322ea31e Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Thu, 2 Jun 2022 21:05:40 -0400 Subject: [PATCH v3] bindat: Improve str, strz documentation * doc/lispref/processes.texi (Bindat Types): Expand the documentation for the `str' and `strz' types to clarify expectations and explain edge case behavior. --- doc/lispref/processes.texi | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/doc/lispref/processes.texi b/doc/lispref/processes.texi index 668a577870..a93a617c8a 100644 --- a/doc/lispref/processes.texi +++ b/doc/lispref/processes.texi @@ -3479,11 +3479,41 @@ Bindat Types @var{bitlen} has to be a multiple of 8. @item str @var{len} -String of bytes of length @var{len}. +Unibyte string (@pxref{Text Representations}) of length @var{len}. +When packing, the first @var{len} bytes of the input string are copied +to the packed output. If the input string is shorter than @var{len}, +the remaining bytes will be null (zero) unless a pre-allocated string +was provided to @code{bindat-pack}, in which case the remaining bytes +are left unmodified. When unpacking, any null bytes in the packed +input string will appear in the unpacked output. @item strz &optional @var{len} -Zero-terminated string of bytes, can be of arbitrary length or in a fixed-size -field with length @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 +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 +bytes. When unpacking, the resulting string contains all bytes up to +(but excluding) the null byte. + +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 +unpacked result. + +@quotation Caution +The packed output will not be null-terminated unless one of the +following is true: +@itemize +@item +The input string is shorter than @var{len} and either no pre-allocated +string was provided to @code{bindat-pack} or the appropriate byte in +the pre-allocated string was already null. +@item +The input string contains a null byte within the first @var{len} +bytes. +@end itemize +@end quotation @item vec @var{len} [@var{type}] Vector of @var{len} elements. The type of the elements is given by -- 2.36.1