Change in openvpn[master]: service: add utf8to16 function that takes a size
A message that is not in the archive (sent off-list or not yet received): gerrit.1733989644000.I6b4aa3d63c0b684bf95841271c04bc5d9c37793b@...2715...
Attention is currently required from: flichtenheld, plaisthos.
Hello plaisthos, flichtenheld,
I'd like you to do a code review.
Please visit
http://gerrit.openvpn.net/c/openvpn/+/836?usp=email
to review the following change.
Change subject: service: add utf8to16 function that takes a size
......................................................................
service: add utf8to16 function that takes a size
utf8to16_size() takes the size of the to be converted string. This is needed to convert MULTI_SZ strings, which contain inline NUL characters, but can be useful in other cases as well.
---
M src/openvpnserv/common.c
M src/openvpnserv/service.h
2 files changed, 37 insertions(+), 6 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/836/1
src/openvpnserv/common.c +3 -4
@@ -247,17 +247,16 @@return error; } -/* Convert a utf8 string to utf16. Caller should free the result */ wchar_t * -utf8to16 (const char *utf8) +utf8to16_size (const char *utf8,int size) { -int n =MultiByteToWideChar (CP_UTF8 ,0 , utf8,-1 ,NULL ,0 ); +int n =MultiByteToWideChar (CP_UTF8 ,0 , utf8, size,NULL ,0 );wchar_t *utf16 =malloc (n *sizeof (wchar_t));if (!utf16) {return NULL ; } -MultiByteToWideChar (CP_UTF8 ,0 , utf8,-1 , utf16, n); +MultiByteToWideChar (CP_UTF8 ,0 , utf8, size, utf16, n);return utf16; }
src/openvpnserv/service.h +34 -2
@@ -89,8 +89,40 @@DWORD MsgToEventLog (DWORD flags,LPCTSTR lpszMsg, ...); -/* Convert a utf8 string to utf16. Caller should free the result */ -wchar_t *utf8to16 (const char *utf8); +/** +* Convert a UTF-8 string to UTF-16 +* +* The size parameter can be used to convert strings which contain inline NUL +* characters, like MULTI_SZ strings used as values in the registry do, +* or (sub)strings that are not zero terminated. If size is -1 the length +* of the string is determined automatically by the WIN32 API. Make sure +* you pass a terminated string or else bad things will happen. Note that +* the size you pass should always include the terminating zero as well. +* +* If the returned string is not NULL it must be freed by the caller. +* +* @param utf8 const string to be converted +* @param size the size of the string +* +* @return wchar_t* heap allocated result string +*/ +wchar_t *utf8to16_size (const char *utf8,int size); + +/** +* Convert a zero terminated UTF-8 string to UTF-16 +* +* This is just a wrapper function that always passes -1 as string size +* to \ref utf8to16_size. +* +* @param utf8 const string to be converted +* +* @return wchar_t* heap allocated result string +*/ +inline wchar_t * +utf8to16 (const char *utf8) +{ +return utf8to16_size (utf8,-1 ); +}/* return windows system directory as a pointer to a static string */ const wchar_t *get_win_sys_path (void );
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/836?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6b4aa3d63c0b684bf95841271c04bc5d9c37793b
Gerrit-Change-Number: 836
Gerrit-PatchSet: 1
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: d12fk, plaisthos.
flichtenheld has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/836?usp=email )
Change subject: service: add utf8to16 function that takes a size
......................................................................
Patch Set 1: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/836?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6b4aa3d63c0b684bf95841271c04bc5d9c37793b
Gerrit-Change-Number: 836
Gerrit-PatchSet: 1
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Comment-Date: Fri, 13 Dec 2024 16:44:23 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH 1/1 service: add utf8to16 function that takes a size
In reply to a message not in the archiveFrom: Heiko Hund <[email protected]...>
utf8to16_size() takes the size of the to be converted string. This is needed to convert MULTI_SZ strings, which contain inline NUL characters, but can be useful in other cases as well.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/836
This mail reflects revision 1 of this Change.
Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <[email protected]...>
src/openvpnserv/common.c +3 -4
@@ -247,17 +247,16 @@return error; } -/* Convert a utf8 string to utf16. Caller should free the result */ wchar_t * -utf8to16 (const char *utf8) +utf8to16_size (const char *utf8,int size) { -int n =MultiByteToWideChar (CP_UTF8 ,0 , utf8,-1 ,NULL ,0 ); +int n =MultiByteToWideChar (CP_UTF8 ,0 , utf8, size,NULL ,0 );wchar_t *utf16 =malloc (n *sizeof (wchar_t));if (!utf16) {return NULL ; } -MultiByteToWideChar (CP_UTF8 ,0 , utf8,-1 , utf16, n); +MultiByteToWideChar (CP_UTF8 ,0 , utf8, size, utf16, n);return utf16; }
src/openvpnserv/service.h +34 -2
@@ -89,8 +89,40 @@DWORD MsgToEventLog (DWORD flags,LPCTSTR lpszMsg, ...); -/* Convert a utf8 string to utf16. Caller should free the result */ -wchar_t *utf8to16 (const char *utf8); +/** +* Convert a UTF-8 string to UTF-16 +* +* The size parameter can be used to convert strings which contain inline NUL +* characters, like MULTI_SZ strings used as values in the registry do, +* or (sub)strings that are not zero terminated. If size is -1 the length +* of the string is determined automatically by the WIN32 API. Make sure +* you pass a terminated string or else bad things will happen. Note that +* the size you pass should always include the terminating zero as well. +* +* If the returned string is not NULL it must be freed by the caller. +* +* @param utf8 const string to be converted +* @param size the size of the string +* +* @return wchar_t* heap allocated result string +*/ +wchar_t *utf8to16_size (const char *utf8,int size); + +/** +* Convert a zero terminated UTF-8 string to UTF-16 +* +* This is just a wrapper function that always passes -1 as string size +* to \ref utf8to16_size. +* +* @param utf8 const string to be converted +* +* @return wchar_t* heap allocated result string +*/ +inline wchar_t * +utf8to16 (const char *utf8) +{ +return utf8to16_size (utf8,-1 ); +}/* return windows system directory as a pointer to a static string */ const wchar_t *get_win_sys_path (void );
Attention is currently required from: d12fk, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/836?usp=email )
Change subject: service: add utf8to16 function that takes a size
......................................................................
Patch Set 1: Code-Review-2
(1 comment)
Patchset:
PS1:
Breaks GHA MinGW builds for me :-(
https://github.com/cron2/openvpn/actions/runs/12438329894/job/34730024149
``` /usr/bin/i686-w64-mingw32-ld: src/openvpnserv/CMakeFiles/openvpnserv.dir/Debug/interactive.c.obj: in function `InterfaceLuid': 2474 /home/runner/work/openvpn/openvpn/src/openvpnserv/interactive.c:554: undefined reference to `utf8to16' 2475 /usr/bin/i686-w64-mingw32-ld: src/openvpnserv/CMakeFiles/openvpnserv.dir/Debug/interactive.c.obj: in function `SetDNSDomain': 2476 /home/runner/work/openvpn/openvpn/src/openvpnserv/interactive.c:1242: undefined reference to `utf8to16' 2477 /usr/bin/i686-w64-mingw32-ld: src/openvpnserv/CMakeFiles/openvpnserv.dir/Debug/interactive.c.obj: in function `HandleDNSConfigMessage': 2478 /home/runner/work/openvpn/openvpn/src/openvpnserv/interactive.c:1297: undefined reference to `utf8to16' 2479 /usr/bin/i686-w64-mingw32-ld: src/openvpnserv/CMakeFiles/openvpnserv.dir/Debug/interactive.c.obj: in function `HandleWINSConfigMessage': 2480 /home/runner/work/openvpn/openvpn/src/openvpnserv/interactive.c:1394: undefined reference to `utf8to16' ```
so it seems the macro definition is not included "in the right places". Does this need another patch to be applied as prerequisite?
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/836?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6b4aa3d63c0b684bf95841271c04bc5d9c37793b
Gerrit-Change-Number: 836
Gerrit-PatchSet: 1
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Comment-Date: Fri, 20 Dec 2024 21:07:33 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
Attention is currently required from: d12fk, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/836?usp=email )
Change subject: service: add utf8to16 function that takes a size
......................................................................
Patch Set 1:
(1 comment)
File src/openvpnserv/service.h:
http://gerrit.openvpn.net/c/openvpn/+/836/comment/84ac0384_0496d81f :
PS1, Line 121: inline wchar_t *static inline... will fix the MinGW builds. I forgot why this is needed, but all our other inlines-in-headers also have a static.
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/836?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6b4aa3d63c0b684bf95841271c04bc5d9c37793b
Gerrit-Change-Number: 836
Gerrit-PatchSet: 1
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Comment-Date: Fri, 20 Dec 2024 21:17:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment
Attention is currently required from: d12fk, flichtenheld, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/836?usp=email
to look at the new patch set (#2).
The following approvals got outdated and were removed:
Code-Review+2 by flichtenheld
Change subject: service: add utf8to16 function that takes a size
......................................................................
service: add utf8to16 function that takes a size
utf8to16_size() takes the size of the to be converted string. This is needed to convert MULTI_SZ strings, which contain inline NUL characters, but can be useful in other cases as well.
---
M src/openvpnserv/common.c
M src/openvpnserv/service.h
2 files changed, 37 insertions(+), 6 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/836/2
src/openvpnserv/common.c +3 -4
@@ -247,17 +247,16 @@return error; } -/* Convert a utf8 string to utf16. Caller should free the result */ wchar_t * -utf8to16 (const char *utf8) +utf8to16_size (const char *utf8,int size) { -int n =MultiByteToWideChar (CP_UTF8 ,0 , utf8,-1 ,NULL ,0 ); +int n =MultiByteToWideChar (CP_UTF8 ,0 , utf8, size,NULL ,0 );wchar_t *utf16 =malloc (n *sizeof (wchar_t));if (!utf16) {return NULL ; } -MultiByteToWideChar (CP_UTF8 ,0 , utf8,-1 , utf16, n); +MultiByteToWideChar (CP_UTF8 ,0 , utf8, size, utf16, n);return utf16; }
src/openvpnserv/service.h +34 -2
@@ -89,8 +89,40 @@DWORD MsgToEventLog (DWORD flags,LPCTSTR lpszMsg, ...); -/* Convert a utf8 string to utf16. Caller should free the result */ -wchar_t *utf8to16 (const char *utf8); +/** +* Convert a UTF-8 string to UTF-16 +* +* The size parameter can be used to convert strings which contain inline NUL +* characters, like MULTI_SZ strings used as values in the registry do, +* or (sub)strings that are not zero terminated. If size is -1 the length +* of the string is determined automatically by the WIN32 API. Make sure +* you pass a terminated string or else bad things will happen. Note that +* the size you pass should always include the terminating zero as well. +* +* If the returned string is not NULL it must be freed by the caller. +* +* @param utf8 const string to be converted +* @param size the size of the string +* +* @return wchar_t* heap allocated result string +*/ +wchar_t *utf8to16_size (const char *utf8,int size); + +/** +* Convert a zero terminated UTF-8 string to UTF-16 +* +* This is just a wrapper function that always passes -1 as string size +* to \ref utf8to16_size. +* +* @param utf8 const string to be converted +* +* @return wchar_t* heap allocated result string +*/ +static inline wchar_t * +utf8to16 (const char *utf8) +{ +return utf8to16_size (utf8,-1 ); +}/* return windows system directory as a pointer to a static string */ const wchar_t *get_win_sys_path (void );
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/836?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6b4aa3d63c0b684bf95841271c04bc5d9c37793b
Gerrit-Change-Number: 836
Gerrit-PatchSet: 2
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-MessageType: newpatchset
Attention is currently required from: cron2, flichtenheld, plaisthos.
d12fk has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/836?usp=email )
Change subject: service: add utf8to16 function that takes a size
......................................................................
Patch Set 2:
(1 comment)
File src/openvpnserv/service.h:
http://gerrit.openvpn.net/c/openvpn/+/836/comment/f01bb7b9_83021c13 :
PS1, Line 121: inline wchar_t *
Quoted 1 line
static inline...will fix the MinGW builds. […]
Done
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/836?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6b4aa3d63c0b684bf95841271c04bc5d9c37793b
Gerrit-Change-Number: 836
Gerrit-PatchSet: 2
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Sat, 21 Dec 2024 22:40:54 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: cron2 <[email protected]...>
Gerrit-MessageType: comment
Attention is currently required from: d12fk, flichtenheld, plaisthos.
cron2 has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/836?usp=email )
Change subject: service: add utf8to16 function that takes a size
......................................................................
Patch Set 2: Code-Review+2
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/836?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6b4aa3d63c0b684bf95841271c04bc5d9c37793b
Gerrit-Change-Number: 836
Gerrit-PatchSet: 2
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Attention: d12fk <[email protected]...>
Gerrit-Comment-Date: Sat, 21 Dec 2024 22:41:15 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
PATCH v2 1/1 service: add utf8to16 function that takes a size
In reply to a message not in the archiveFrom: Heiko Hund <[email protected]...>
utf8to16_size() takes the size of the to be converted string. This is needed to convert MULTI_SZ strings, which contain inline NUL characters, but can be useful in other cases as well.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/836
This mail reflects revision 2 of this Change.
Acked-by according to Gerrit (reflected above):
Gert Doering <[email protected]...>
src/openvpnserv/common.c +3 -4
@@ -247,17 +247,16 @@return error; } -/* Convert a utf8 string to utf16. Caller should free the result */ wchar_t * -utf8to16 (const char *utf8) +utf8to16_size (const char *utf8,int size) { -int n =MultiByteToWideChar (CP_UTF8 ,0 , utf8,-1 ,NULL ,0 ); +int n =MultiByteToWideChar (CP_UTF8 ,0 , utf8, size,NULL ,0 );wchar_t *utf16 =malloc (n *sizeof (wchar_t));if (!utf16) {return NULL ; } -MultiByteToWideChar (CP_UTF8 ,0 , utf8,-1 , utf16, n); +MultiByteToWideChar (CP_UTF8 ,0 , utf8, size, utf16, n);return utf16; }
src/openvpnserv/service.h +34 -2
@@ -89,8 +89,40 @@DWORD MsgToEventLog (DWORD flags,LPCTSTR lpszMsg, ...); -/* Convert a utf8 string to utf16. Caller should free the result */ -wchar_t *utf8to16 (const char *utf8); +/** +* Convert a UTF-8 string to UTF-16 +* +* The size parameter can be used to convert strings which contain inline NUL +* characters, like MULTI_SZ strings used as values in the registry do, +* or (sub)strings that are not zero terminated. If size is -1 the length +* of the string is determined automatically by the WIN32 API. Make sure +* you pass a terminated string or else bad things will happen. Note that +* the size you pass should always include the terminating zero as well. +* +* If the returned string is not NULL it must be freed by the caller. +* +* @param utf8 const string to be converted +* @param size the size of the string +* +* @return wchar_t* heap allocated result string +*/ +wchar_t *utf8to16_size (const char *utf8,int size); + +/** +* Convert a zero terminated UTF-8 string to UTF-16 +* +* This is just a wrapper function that always passes -1 as string size +* to \ref utf8to16_size. +* +* @param utf8 const string to be converted +* +* @return wchar_t* heap allocated result string +*/ +static inline wchar_t * +utf8to16 (const char *utf8) +{ +return utf8to16_size (utf8,-1 ); +}/* return windows system directory as a pointer to a static string */ const wchar_t *get_win_sys_path (void );
[Openvpn-devel] [PATCH applied] Re: service: add utf8to16 function that takes a size
v1 looked like a nice and trivial change with not much to go wrong, and then GHA exploded - one of the builds runs without "-O2", and with an inline function without "static inline" this leads to link time errors (function is not inlined due to missing -O2, but not instantiated either, so "nowhere to be found"). v1 to v2 only differ in the "static", so I'm recording Frank's ACK on v1 plus adding my own.
Your patch has been applied to the master branch.
commit d92df90470a059f0ea231250d85ab47b72bc4791
Author: Heiko Hund Date: Sat Dec 21 23:41:36 2024 +0100
service: add utf8to16 function that takes a size
Signed-off-by: Heiko Hund <[email protected]...>
Acked-by: Frank Lichtenheld <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30158.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
cron2 has uploaded a new patch set (#3) to the change originally created by d12fk. ( http://gerrit.openvpn.net/c/openvpn/+/836?usp=email )
The following approvals got outdated and were removed:
Code-Review+2 by cron2
Change subject: service: add utf8to16 function that takes a size
......................................................................
service: add utf8to16 function that takes a size
utf8to16_size() takes the size of the to be converted string. This is needed to convert MULTI_SZ strings, which contain inline NUL characters, but can be useful in other cases as well.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30158.html
---
M src/openvpnserv/common.c
M src/openvpnserv/service.h
2 files changed, 37 insertions(+), 6 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/36/836/3
src/openvpnserv/common.c +3 -4
@@ -247,17 +247,16 @@return error; } -/* Convert a utf8 string to utf16. Caller should free the result */ wchar_t * -utf8to16 (const char *utf8) +utf8to16_size (const char *utf8,int size) { -int n =MultiByteToWideChar (CP_UTF8 ,0 , utf8,-1 ,NULL ,0 ); +int n =MultiByteToWideChar (CP_UTF8 ,0 , utf8, size,NULL ,0 );wchar_t *utf16 =malloc (n *sizeof (wchar_t));if (!utf16) {return NULL ; } -MultiByteToWideChar (CP_UTF8 ,0 , utf8,-1 , utf16, n); +MultiByteToWideChar (CP_UTF8 ,0 , utf8, size, utf16, n);return utf16; }
src/openvpnserv/service.h +34 -2
@@ -89,8 +89,40 @@DWORD MsgToEventLog (DWORD flags,LPCTSTR lpszMsg, ...); -/* Convert a utf8 string to utf16. Caller should free the result */ -wchar_t *utf8to16 (const char *utf8); +/** +* Convert a UTF-8 string to UTF-16 +* +* The size parameter can be used to convert strings which contain inline NUL +* characters, like MULTI_SZ strings used as values in the registry do, +* or (sub)strings that are not zero terminated. If size is -1 the length +* of the string is determined automatically by the WIN32 API. Make sure +* you pass a terminated string or else bad things will happen. Note that +* the size you pass should always include the terminating zero as well. +* +* If the returned string is not NULL it must be freed by the caller. +* +* @param utf8 const string to be converted +* @param size the size of the string +* +* @return wchar_t* heap allocated result string +*/ +wchar_t *utf8to16_size (const char *utf8,int size); + +/** +* Convert a zero terminated UTF-8 string to UTF-16 +* +* This is just a wrapper function that always passes -1 as string size +* to \ref utf8to16_size. +* +* @param utf8 const string to be converted +* +* @return wchar_t* heap allocated result string +*/ +static inline wchar_t * +utf8to16 (const char *utf8) +{ +return utf8to16_size (utf8,-1 ); +}/* return windows system directory as a pointer to a static string */ const wchar_t *get_win_sys_path (void );
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/836?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6b4aa3d63c0b684bf95841271c04bc5d9c37793b
Gerrit-Change-Number: 836
Gerrit-PatchSet: 3
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/836?usp=email )
Change subject: service: add utf8to16 function that takes a size
......................................................................
service: add utf8to16 function that takes a size
utf8to16_size() takes the size of the to be converted string. This is needed to convert MULTI_SZ strings, which contain inline NUL characters, but can be useful in other cases as well.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30158.html
---
M src/openvpnserv/common.c
M src/openvpnserv/service.h
2 files changed, 37 insertions(+), 6 deletions(-)
src/openvpnserv/common.c +3 -4
@@ -247,17 +247,16 @@return error; } -/* Convert a utf8 string to utf16. Caller should free the result */ wchar_t * -utf8to16 (const char *utf8) +utf8to16_size (const char *utf8,int size) { -int n =MultiByteToWideChar (CP_UTF8 ,0 , utf8,-1 ,NULL ,0 ); +int n =MultiByteToWideChar (CP_UTF8 ,0 , utf8, size,NULL ,0 );wchar_t *utf16 =malloc (n *sizeof (wchar_t));if (!utf16) {return NULL ; } -MultiByteToWideChar (CP_UTF8 ,0 , utf8,-1 , utf16, n); +MultiByteToWideChar (CP_UTF8 ,0 , utf8, size, utf16, n);return utf16; }
src/openvpnserv/service.h +34 -2
@@ -89,8 +89,40 @@DWORD MsgToEventLog (DWORD flags,LPCTSTR lpszMsg, ...); -/* Convert a utf8 string to utf16. Caller should free the result */ -wchar_t *utf8to16 (const char *utf8); +/** +* Convert a UTF-8 string to UTF-16 +* +* The size parameter can be used to convert strings which contain inline NUL +* characters, like MULTI_SZ strings used as values in the registry do, +* or (sub)strings that are not zero terminated. If size is -1 the length +* of the string is determined automatically by the WIN32 API. Make sure +* you pass a terminated string or else bad things will happen. Note that +* the size you pass should always include the terminating zero as well. +* +* If the returned string is not NULL it must be freed by the caller. +* +* @param utf8 const string to be converted +* @param size the size of the string +* +* @return wchar_t* heap allocated result string +*/ +wchar_t *utf8to16_size (const char *utf8,int size); + +/** +* Convert a zero terminated UTF-8 string to UTF-16 +* +* This is just a wrapper function that always passes -1 as string size +* to \ref utf8to16_size. +* +* @param utf8 const string to be converted +* +* @return wchar_t* heap allocated result string +*/ +static inline wchar_t * +utf8to16 (const char *utf8) +{ +return utf8to16_size (utf8,-1 ); +}/* return windows system directory as a pointer to a static string */ const wchar_t *get_win_sys_path (void );
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/836?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6b4aa3d63c0b684bf95841271c04bc5d9c37793b
Gerrit-Change-Number: 836
Gerrit-PatchSet: 3
Gerrit-Owner: d12fk <[email protected]...>
Gerrit-Reviewer: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged