cloudbase / wnbd

Windows Ceph RBD NBD driver
GNU Lesser General Public License v2.1
57 stars 26 forks source link

driver: fix unicode initialization #109

Closed petrutlucian94 closed 1 year ago

petrutlucian94 commented 1 year ago

The RtlInitUnicodeString docs [1] suggest us to use the RTL_CONSTANT_STRING macro when initializing UNICODE_STRING structures. There's even the following reference:

UNICODE_STRING RTL_CONSTANT_STRING( [in] PCWSTR SourceString );

However, RTL_CONSTANT_STRING uses sizeof, so it's going to use the size of the pointer instead of the string length.

Visual studio will throw a warning but only for the "Analyze" builds:

C:\workspace\wnbd\driver\options.c(250): warning C28132: Taking the size of pointer Name: This will yield the size of a pointer (4 or 8), not the size of the object pointed to. Dereference the pointer, or if the size of a pointer was intended, use the pointer type or (void *) instead.

That being considered, we'll just use RtlInitUnicodeString instead.

Signed-off-by: Lucian Petrut lpetrut@cloudbasesolutions.com