Module Name: src Committed By: riastradh Date: Tue Aug 20 20:36:30 UTC 2024
Modified Files: src/lib/libc/locale: c16rtomb.3 c32rtomb.3 c8rtomb.3 Log Message: c8rtomb(3), c16rtomb(3), c32rtomb(3): Fix null string output case. This ignores c8/c16/c32, produces no output anywhere, and just resets ps to the initial conversion state. Also just use 0 in the example, not '\0' or L'\0'. This works for C11, which prefers '\0' and L'\0', for and C23, which introduced the new u8'\0', u'\0' (UTF-16), and U'\0' (UTF-32). To generate a diff of this commit: cvs rdiff -u -r1.10 -r1.11 src/lib/libc/locale/c16rtomb.3 \ src/lib/libc/locale/c32rtomb.3 cvs rdiff -u -r1.8 -r1.9 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.10 src/lib/libc/locale/c16rtomb.3:1.11 --- src/lib/libc/locale/c16rtomb.3:1.10 Tue Aug 20 20:04:45 2024 +++ src/lib/libc/locale/c16rtomb.3 Tue Aug 20 20:36:30 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: c16rtomb.3,v 1.10 2024/08/20 20:04:45 riastradh Exp $ +.\" $NetBSD: c16rtomb.3,v 1.11 2024/08/20 20:36:30 riastradh Exp $ .\" .\" Copyright (c) 2024 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -71,9 +71,17 @@ to denote error. .Pp If .Fa s -is a null pointer, no output is stored, but the effects on +is a null pointer, +no output is produced and +.Fa ps +is reset to the initial conversion state, as if the call had been +.Fo c8rtomb +.Va buf , +.Li 0 , .Fa ps -and the return value are unchanged. +.Fc +for some internal buffer +.Va buf . .Pp If .Fa c16 @@ -132,7 +140,7 @@ for (i = 0; i < __arraycount(c16); i++) assert(len < sizeof(buf) - (s - buf)); s += len; } -len = c16rtomb(s, L'\e0', &mbs); /* NUL-terminate */ +len = c16rtomb(s, 0, &mbs); /* NUL-terminate */ if (len == (size_t)-1) err(1, "c16rtomb"); assert(len <= sizeof(buf) - (s - buf)); Index: src/lib/libc/locale/c32rtomb.3 diff -u src/lib/libc/locale/c32rtomb.3:1.10 src/lib/libc/locale/c32rtomb.3:1.11 --- src/lib/libc/locale/c32rtomb.3:1.10 Tue Aug 20 20:04:45 2024 +++ src/lib/libc/locale/c32rtomb.3 Tue Aug 20 20:36:30 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: c32rtomb.3,v 1.10 2024/08/20 20:04:45 riastradh Exp $ +.\" $NetBSD: c32rtomb.3,v 1.11 2024/08/20 20:36:30 riastradh Exp $ .\" .\" Copyright (c) 2024 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -79,9 +79,17 @@ is an integer either in [0,0xd7ff] or in .Pp If .Fa s -is a null pointer, no output is stored, but the effects on +is a null pointer, +no output is produced and +.Fa ps +is reset to the initial conversion state, as if the call had been +.Fo c8rtomb +.Va buf , +.Li 0 , .Fa ps -and the return value are unchanged. +.Fc +for some internal buffer +.Va buf . .Pp If .Fa c32 @@ -138,7 +146,7 @@ for (i = 0; i < __arraycount(c32); i++) assert(len < sizeof(buf) - (s - buf)); s += len; } -len = c32rtomb(s, L'\e0', &mbs); /* NUL-terminate */ +len = c32rtomb(s, 0, &mbs); /* NUL-terminate */ if (len == (size_t)-1) err(1, "c32rtomb"); assert(len <= sizeof(buf) - (s - buf)); Index: src/lib/libc/locale/c8rtomb.3 diff -u src/lib/libc/locale/c8rtomb.3:1.8 src/lib/libc/locale/c8rtomb.3:1.9 --- src/lib/libc/locale/c8rtomb.3:1.8 Tue Aug 20 20:04:45 2024 +++ src/lib/libc/locale/c8rtomb.3 Tue Aug 20 20:36:30 2024 @@ -1,4 +1,4 @@ -.\" $NetBSD: c8rtomb.3,v 1.8 2024/08/20 20:04:45 riastradh Exp $ +.\" $NetBSD: c8rtomb.3,v 1.9 2024/08/20 20:36:30 riastradh Exp $ .\" .\" Copyright (c) 2024 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -71,9 +71,17 @@ to denote error. .Pp If .Fa s -is a null pointer, no output is stored, but the effects on +is a null pointer, +no output is produced and +.Fa ps +is reset to the initial conversion state, as if the call had been +.Fo c8rtomb +.Va buf , +.Li 0 , .Fa ps -and the return value are unchanged. +.Fc +for some internal buffer +.Va buf . .Pp If .Fa c8 @@ -132,7 +140,7 @@ for (i = 0; i < __arraycount(c8); i++) { assert(len < sizeof(buf) - (s - buf)); s += len; } -len = c8rtomb(s, '\e0', &mbs); /* NUL-terminate */ +len = c8rtomb(s, 0, &mbs); /* NUL-terminate */ if (len == (size_t)-1) err(1, "c16rtomb"); assert(len <= sizeof(buf) - (s - buf));