summaryrefslogtreecommitdiff
path: root/source3/rpc_parse
diff options
context:
space:
mode:
authorGerald Carter <jerry@samba.org>2000-08-08 06:59:35 +0000
committerGerald Carter <jerry@samba.org>2000-08-08 06:59:35 +0000
commit3a123d2572d91b648e2046a9fa1c0795ce680d3d (patch)
tree14af1d9dbba2339bd603bd6f4e46014dfd2214b8 /source3/rpc_parse
parentf296a8d087be261fee51a3a4664685bab1fb5ab1 (diff)
downloadsamba-3a123d2572d91b648e2046a9fa1c0795ce680d3d.tar.gz
samba-3a123d2572d91b648e2046a9fa1c0795ce680d3d.tar.bz2
samba-3a123d2572d91b648e2046a9fa1c0795ce680d3d.zip
cleanup in init_unistr2_from_unistr()
--jerry (This used to be commit 1e00ac19cd001024fa8007eff5137aac877796fa)
Diffstat (limited to 'source3/rpc_parse')
-rw-r--r--source3/rpc_parse/parse_misc.c46
1 files changed, 19 insertions, 27 deletions
diff --git a/source3/rpc_parse/parse_misc.c b/source3/rpc_parse/parse_misc.c
index c22f1a5d2e..617552009c 100644
--- a/source3/rpc_parse/parse_misc.c
+++ b/source3/rpc_parse/parse_misc.c
@@ -873,45 +873,37 @@ void init_unistr2(UNISTR2 *str, const char *buf, size_t len)
void init_unistr2_from_unistr (UNISTR2 *to, UNISTR *from)
{
- BOOL found;
- uint32 i = 0;
+ uint32 i;
- if ((to == NULL) || (from == NULL) || (from->buffer == NULL))
- return;
-
- ZERO_STRUCTP (to);
+ /* the destination UNISTR2 should never be NULL.
+ if it is it is a programming error */
- /* get the length; UNISTR **are** NULL terminated */
- found = False;
- while (!found)
- {
- if ((from->buffer)[i]=='\0')
- found = True;
- else
- i++;
- }
- i++;
-
- if (!found)
- {
- DEBUG(0,("init_unistr2_from_unistr: non-null terminiated UNISTR!\n"));
+ /* if the source UNISTR is NULL, then zero out
+ the destination string and return */
+ ZERO_STRUCTP (to);
+ if ((from == NULL) || (from->buffer == NULL))
return;
- }
- /* set up string lengths. */
- to->uni_max_len = i;
+ /* get the length; UNISTR must be NULL terminated */
+ i = 0;
+ while ((from->buffer)[i]!='\0')
+ i++;
+
+ /* set up string lengths; uni_max_len is set to i+1
+ because we need to account for the final NULL termination */
+ to->uni_max_len = i+1;
to->undoc = 0;
- to->uni_str_len = i;
+ to->uni_str_len = i+1;
if (!parse_misc_talloc)
parse_misc_talloc = talloc_init();
- /* copy the string now */
+ /* allocate the space and copy the string buffer */
to->buffer = (uint16 *)talloc(parse_misc_talloc, sizeof(uint16)*(to->uni_str_len));
if (to->buffer == NULL)
smb_panic("init_unistr2_from_unistr: malloc fail\n");
-
- memcpy( to->buffer, from->buffer, to->uni_str_len*sizeof(uint16) );
+ memcpy(to->buffer, from->buffer, to->uni_max_len*sizeof(uint16));
+
return;
}