From 7ae329e6630a07d29f83b6dd4572d26ab8a18c71 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 23 Nov 2003 10:50:52 +0000 Subject: [PATCH] Add a strlen_m_term() function for returning the length of a string including the termination. Using value(strlen_m((r->name)+1)*2) gives the wrong answer for the NULL string. --- source/lib/util_str.c | 15 +++++++++++++++ source/librpc/idl/winreg.idl | 4 ++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/source/lib/util_str.c b/source/lib/util_str.c index 285b0cc02eb..6005a3e49a0 100644 --- a/source/lib/util_str.c +++ b/source/lib/util_str.c @@ -1091,6 +1091,21 @@ size_t strlen_m(const char *s) return count + strlen_w(tmpbuf); } +/** + Work out the number of multibyte chars in a string, including the NULL + terminator. +**/ +size_t strlen_m_term(const char *s) +{ + size_t count = 0; + + if (!s) { + return 0; + } + + return strlen_m(s) + 1; +} + /** Convert a string to upper case. **/ diff --git a/source/librpc/idl/winreg.idl b/source/librpc/idl/winreg.idl index c7dc3942dfc..263946bdda9 100644 --- a/source/librpc/idl/winreg.idl +++ b/source/librpc/idl/winreg.idl @@ -10,8 +10,8 @@ ] interface winreg { typedef struct { - [value(2*(strlen_m(r->name)+1))] uint16 name_len; - [value(r->name_len)] uint16 name_size; + [value(strlen_m_term(r->name)*2)] uint16 name_len; + [value(r->name_len)] uint16 name_size; unistr *name; } winreg_String;