Re: g_strndup()



"David C. Mason" wrote:
> 
> Hi guys,
> 
> Robey Pointer from Eazel pointed this out to me...
> 
> > The glib documentation states that for g_strndup(), "n" must be less
> > than or equal to the length of the original string.  That's not
> > true: "n" can be greater than the length of the string.  More memory
> > will be allocated than you necessarily needed, but the returned
> > string will be of length <= n, and it will be null terminated, so
> > the end result is success.
> 
> Is this correct? Should we update as such?

Yes, it is correct.

I'll change it to this, unless someone suggests something better:

<!-- ##### FUNCTION g_strndup ##### -->
<para>
Duplicates the first @n characters of a string, returning a newly-allocated
buffer @n + 1 characters long which will always be null-terminated.
If @str is less than @n characters long the buffer is padded with nulls.
The returned value should be freed when no longer needed.
</para>

@str: the string to duplicate part of.
@n: the maximum number of characters to copy from @str.
@Returns: a newly-allocated buffer containing the first @n characters of @str,
null-terminated.


Damon






[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]