This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Overlapped Buffers for string functions


On Tue, May 12, 2009 at 3:52 PM, Sankar P <sankar.curiosity@gmail.com> wrote:
> Hi,
>
> I have two questions.
>
> In my attempt to become one of the Geeks, I was trying to fix a kernel
> bug - http://bugzilla.kernel.org/show_bug.cgi?id=12966

I understand that the sprintf used by kernel is not coming from libc,
but internal to kernel source. I just got curios to understand the
issue.


>
> I came across the sprintf function, and I was told that the source and
> destination buffers should not overlap i.e.,
>
> sprintf(buffer, "%s appended", buffer);
>
> is a wrong usage and how it should be used is, like:
>
> sprintf(buffer + strlen(buffer), " appended");
>
>
>
> (1) Is this correct ?
> I could not find this information from the man pages.
>
> I belive that appending to a string is a common usecase and a new api
> could be very handy in a lot of places.
>
> saprintf = string append printf
>
> char * buffer saprintf (char *buffer, const char * format, ...);
>
> This function internally could do just,
>
> ? ? ? ? ? ? ? ?sprintf (buffer + strlen (buffer), format, ...);
>
> + plus other error checks
>
> (2) Is it okay to implement this new api - saprintf ? ?I am willing to
> give a patch, if the idea is approved.
>
>
> Are there any other better methods that I am overlooking ?
>
>
> I am not subscribed to the list, so please add my address in CC while
> replying. Thanks.
>
> --
> Sankar
> http://psankar.blogspot.com
>

--
Sankar
http://psankar.blogspot.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]