Module Name: src Committed By: riastradh Date: Tue Aug 20 17:14:05 UTC 2024
Modified Files: src/lib/libc/locale: c16rtomb.3 c32rtomb.3 c8rtomb.3 Log Message: c8rtomb(3), c16rtomb(3), c32rtomb(3): Suggest MB_LEN_MAX in example. This way it avoids variable-length arrays, by always allocating the maximum space that could be occupied by MB_CUR_MAX. To generate a diff of this commit: cvs rdiff -u -r1.8 -r1.9 src/lib/libc/locale/c16rtomb.3 \ src/lib/libc/locale/c32rtomb.3 cvs rdiff -u -r1.6 -r1.7 src/lib/libc/locale/c8rtomb.3 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/locale/c16rtomb.3 diff -u src/lib/libc/locale/c16rtomb.3:1.8 src/lib/libc/locale/c16rtomb.3:1.9 --- src/lib/libc/locale/c16rtomb.3:1.8 Sun Aug 18 02:19:35 2024 +++ src/lib/libc/locale/c16rtomb.3 Tue Aug 20 17:14:05 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: c16rtomb.3,v 1.8 2024/08/18 02:19:35 riastradh Exp $ +.\" $NetBSD: c16rtomb.3,v 1.9 2024/08/20 17:14:05 riastradh Exp $ .\" .\" Copyright (c) 2024 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -145,7 +145,7 @@ NUL-terminate it (with any shift sequenc state), and print it: .Bd -literal -offset indent char16_t c16[] = { 0xd83d, 0xdca9 }; -char buf[(__arraycount(c16) + 1)*MB_CUR_MAX], *s = buf; +char buf[(__arraycount(c16) + 1)*MB_LEN_MAX], *s = buf; size_t i; mbstate_t mbs = {0}; /* initial conversion state */ @@ -164,6 +164,11 @@ if (len == (size_t)-1) assert(len <= sizeof(buf) - (s - buf)); printf("%s\en", buf); .Ed +.Pp +To avoid a variable-length array, this code uses +.Dv MB_LEN_MAX , +which is a constant upper bound on the locale-dependent +.Dv MB_CUR_MAX . .\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .Sh ERRORS .Bl -tag -width Bq Index: src/lib/libc/locale/c32rtomb.3 diff -u src/lib/libc/locale/c32rtomb.3:1.8 src/lib/libc/locale/c32rtomb.3:1.9 --- src/lib/libc/locale/c32rtomb.3:1.8 Sun Aug 18 02:19:35 2024 +++ src/lib/libc/locale/c32rtomb.3 Tue Aug 20 17:14:05 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: c32rtomb.3,v 1.8 2024/08/18 02:19:35 riastradh Exp $ +.\" $NetBSD: c32rtomb.3,v 1.9 2024/08/20 17:14:05 riastradh Exp $ .\" .\" Copyright (c) 2024 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -128,7 +128,7 @@ NUL-terminate it (with any shift sequenc state), and print it: .Bd -literal -offset indent char32_t c32[] = { 0x1f4a9, 0x20ac, 0x21 }; -char buf[(__arraycount(c32) + 1)*MB_CUR_MAX], *s = buf; +char buf[(__arraycount(c32) + 1)*MB_LEN_MAX], *s = buf; size_t i; mbstate_t mbs = {0}; /* initial conversion state */ @@ -147,6 +147,10 @@ if (len == (size_t)-1) assert(len <= sizeof(buf) - (s - buf)); printf("%s\en", buf); .Ed +To avoid a variable-length array, this code uses +.Dv MB_LEN_MAX , +which is a constant upper bound on the locale-dependent +.Dv MB_CUR_MAX . .\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .Sh ERRORS .Bl -tag -width Bq Index: src/lib/libc/locale/c8rtomb.3 diff -u src/lib/libc/locale/c8rtomb.3:1.6 src/lib/libc/locale/c8rtomb.3:1.7 --- src/lib/libc/locale/c8rtomb.3:1.6 Sun Aug 18 02:19:35 2024 +++ src/lib/libc/locale/c8rtomb.3 Tue Aug 20 17:14:05 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: c8rtomb.3,v 1.6 2024/08/18 02:19:35 riastradh Exp $ +.\" $NetBSD: c8rtomb.3,v 1.7 2024/08/20 17:14:05 riastradh Exp $ .\" .\" Copyright (c) 2024 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -145,7 +145,7 @@ NUL-terminate it (with any shift sequenc state), and print it: .Bd -literal -offset indent char8_t c8[] = { 0xf0, 0x9f, 0x92, 0xa9 }; -char buf[(__arraycount(c8) + 1)*MB_CUR_MAX], *s = buf; +char buf[(__arraycount(c8) + 1)*MB_LEN_MAX], *s = buf; size_t i; mbstate_t mbs = {0}; /* initial conversion state */ @@ -164,6 +164,11 @@ if (len == (size_t)-1) assert(len <= sizeof(buf) - (s - buf)); printf("%s\en", buf); .Ed +.Pp +To avoid a variable-length array, this code uses +.Dv MB_LEN_MAX , +which is a constant upper bound on the locale-dependent +.Dv MB_CUR_MAX . .\""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" .Sh ERRORS .Bl -tag -width Bq