Re: [PATCH 1/3] add git_psprintf helper function
- From
- Jonathan Tan <jonathantanmy@google.com>
- Date
- Feb 16, 2017, 15:51 UTC
- Message-ID
- <616a2b08-71f9-d594-d46c-2687bf20ae2b@google.com>
- In-Reply-To
- <20170216112829.18079-2-franchesko.salias.hudro.pedros@gmail.com>
On 02/16/2017 03:28 AM, Maxim Moseychuk wrote:
Show 13 quoted lines
> There are a number of places in the code where we call > xsnprintf(), with the assumption that the output will fit into > the buffer. If the buffer is small, then git die. > In many places buffers have compile-time size, but generated string > depends from current system locale (gettext)and can have size > greater the buffer. > Just run "LANG=ru_RU.UTF8 git bisect start v4.9 v4.8" > on linux sources - it impossible. > > git_psprintf is similar to the standard C sprintf() function > but safer, since it calculates the maximum space required > and allocates memory to hold the result. > The returned string should be freed with free() when no longer needed.
If I understand this correctly, xstrfmt (in strbuf.h) should already do what you need, so you do not need a new function.