Re-wrote prs_force_grow() as my fist implementation was crap. Now only
authorJeremy Allison <jra@samba.org>
Wed, 28 Apr 1999 22:21:43 +0000 (22:21 +0000)
committerJeremy Allison <jra@samba.org>
Wed, 28 Apr 1999 22:21:43 +0000 (22:21 +0000)
grow by the requested amount in this case.
Jeremy.

source/rpc_parse/parse_prs.c

index f990711eeea51bdbca13d164b4b1894f34529b02..fd4dceed176226cbb9ab2651bea2e3706c63d11e 100644 (file)
@@ -171,33 +171,31 @@ BOOL prs_grow(prs_struct *ps, uint32 extra_space)
 
 /*******************************************************************
  Attempt to force a data buffer to grow by len bytes.
- We do this by setting the current offset to the end of the
- current buffer and then calling prs_grow().
- Also depends on the data stream mode (io).
+ This is only used when appending more data onto a prs_struct
+ when reading an rpc reply, before unmarshalling it.
  ********************************************************************/
 
 BOOL prs_force_grow(prs_struct *ps, uint32 extra_space)
 {
-  uint32 save_current_offset = ps->data_offset;
-  BOOL saved_io = ps->io;
-  BOOL ret;
-
-  ps->data_offset = ps->buffer_size;
-  /* 
-   * Note we have to pretend we're marshalling in order
-   *  for prs_grow to work.
-   */
-  ps->io = MARSHALL;
-
-  ret = prs_grow(ps, extra_space);
-
-  /*
-   * Restore the current offset and also the io method.
-   */
-  ps->data_offset = save_current_offset;
-  ps->io = saved_io;
-
-  return ret;
+       uint32 new_size = ps->buffer_size + extra_space;
+       char *new_data;
+
+       if(!UNMARSHALLING(ps) || !ps->is_dynamic) {
+               DEBUG(0,("prs_force_grow: Buffer overflow - unable to expand buffer by %u bytes.\n",
+                               (unsigned int)extra_space));
+               return False;
+       }
+
+       if((new_data = Realloc(ps->data_p, new_size)) == NULL) {
+               DEBUG(0,("prs_force_grow: Realloc failure for size %u.\n",
+                       (unsigned int)new_size));
+               return False;
+       }
+
+       ps->buffer_size = new_size;
+       ps->data_p = new_data;
+
+       return True;
 }
 
 /*******************************************************************