]> git.feebdaed.xyz Git - 0xmirror/curl.git/commit
idn: clarify null-termination on Windows
authorViktor Szakats <commit@vsz.me>
Mon, 15 Dec 2025 15:49:04 +0000 (16:49 +0100)
committerViktor Szakats <commit@vsz.me>
Tue, 16 Dec 2025 15:30:43 +0000 (16:30 +0100)
commitbe76b32aed8ba5ee96bbd924a3e3fdbe959b321b
treedc230818786c48219784dd8900ec60c60f3ace9b
parent32454b954a2a8ab40f563d271e9e756e157dc67b
idn: clarify null-termination on Windows

Add comments to clarify that a terminating null is always present in
the buffers returned to the caller.

The curl APIs `win32_idn_to_ascii()` or `win32_ascii_to_idn()` receive
a null-terminated UTF-8 string as input. They first convert it to wide
chars by first asking `MultiByteToWideChar()` to calculate the length,
by passing -1. This API returns the length with the null char included
(= `strlen() + 1`), does the conversion, with the output also
null-terminated. `IdnTo*()` preserve this null character as documented.
Then we pass this null-terminated, fixed-length buffer ito
`WideCharToMultiByte()`, which keeps preserving the null, ending up in
the buffer returned to the caller.

Refs:
https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-multibytetowidechar
https://learn.microsoft.com/windows/win32/api/stringapiset/nf-stringapiset-widechartomultibyte
https://learn.microsoft.com/windows/win32/api/winnls/nf-winnls-idntoascii
https://learn.microsoft.com/windows/win32/api/winnls/nf-winnls-idntounicode

WINE source code:
https://gitlab.winehq.org/wine/wine/-/blob/wine-10.20/dlls/kernelbase/locale.c
https://gitlab.winehq.org/wine/wine/-/blob/wine-10.20/dlls/ntdll/locale.c
https://gitlab.winehq.org/wine/wine/-/blob/wine-10.20/dlls/ntdll/locale_private.h

Ref: https://github.com/curl/curl/pull/19976#issuecomment-3656005765
Follow-up to 6694a42aa0e820a6fe1e59d85ff8597b6d768d8d #19798

Closes #19980
lib/idn.c