You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Sean McBride <se...@rogue-research.com> on 2026/06/01 19:35:54 UTC

Re: svn commit: r1934788 - in subversion/trunk/subversion: svn tests/libsvn_subr

On 31 May 2026, at 13:38, Branko Čibej wrote:

> We can't use snprintf() because it's C99. Subversion is written in 
> C90.

You could always do:

#ifdef __APPLE__ || (__STDC_VERSION__ >= 199901L)
   snprintf(...)
#else
   sprintf(...)
#endif

I would not be surprised if Apple removes sprintf() one day, this way 
you'd be ready.

Re: svn commit: r1934788 - in subversion/trunk/subversion: svn tests/libsvn_subr

Posted by Branko Čibej <br...@apache.org>.
On 1. 6. 2026 21:35, Sean McBride wrote:
>
> On 31 May 2026, at 13:38, Branko Čibej wrote:
>
>     We can't use snprintf() because it's C99. Subversion is written in
>     C90.
>
> You could always do:
>
> #ifdef *APPLE* || (*STDC_VERSION* >= 199901L)
> snprintf(...)
> #else
> sprintf(...)
> #endif
>
> I would not be surprised if Apple removes sprintf() one day, this way 
> you'd be ready.
>

If they do, they'll have to remove support for C completely, because 
sprintf() is part of the latest C standard. At that point they won't 
have C compiler any more.

-- Brane

Re: svn commit: r1934788 - in subversion/trunk/subversion: svn tests/libsvn_subr

Posted by Branko Čibej <br...@apache.org>.
On 1. 6. 2026 23:07, Timofei Zhakov wrote:
> On Mon, 01 Jun 2026 at 10:55 PM, Sean McBride 
> <se...@rogue-research.com> wrote:
>
>     On 1 Jun 2026, at 16:46, Branko Čibej wrote:
>
>     > I prefer to just silence the brain-dead warning...
>
>     The warning is hardly brain-dead. sprintf() cannot be implemented
>     safely as it has no idea how big the buffer is. Memory overruns
>     are an infamous problem in C, and using sprintf() in 2026 is
>     madness IMNSHO.
>
>     OpenBSD has this same warning as macOS BTW.
>
>
>
> Well, at the end of the day macos is in fact a BSD based system ;)
>
> About memory safety, if we know the buffer has enough memory, it’s 
> okay. I completely agree with Branko. I believe in that snippet of 
> code, the function is used to format a number which realistically 
> could never exceed like 16 bytes.


5 actually, unless someone tweaks their locale to use numerals that 
aren't in the ASCII subset, in which case it's 11 bytes but still 5 
characters. Oh, it could be more if the locale uses Babylonian or Roman 
numerals, I guess. I won't loose sleep over that remote possibility. I 
don't expect Hammurabi's scribes will use Subversion any time in the 
recent past.


> I wouldn’t say you should avoid a specific function just because you 
> don’t like it or somebody on the internet says so. It’s fine whenever 
> you know what you’re doing.


That's really my problem. This warning caters to the lowest common 
denominator and hurts everyone else. Fine, create a warning flag 
specifically to note these kinds of issues. Apple did that very well 
when they added -W64-to-32 to clang. Don't just "deprecate" a function 
from the standard library that is not deprecated in the standard. 
Whichever standard; if I'm using some POSIX functions, I don't expect 
macOS or any other POSIX compliant system to complain that a function 
was introduced in 2001 and I should use this other function that was 
introduced in 2017 instead.


> Then, some day it leads to Rust rewrites…

That'll come anyway, once the rusties have broken and thrown away all 
other perfectly good code that has worked for the last 30 years.

-- Brane

Re: svn commit: r1934788 - in subversion/trunk/subversion: svn tests/libsvn_subr

Posted by Timofei Zhakov <ti...@chemodax.net>.
On Mon, 01 Jun 2026 at 10:55 PM, Sean McBride <se...@rogue-research.com>
wrote:

> On 1 Jun 2026, at 16:46, Branko Čibej wrote:
>
> > I prefer to just silence the brain-dead warning...
>
> The warning is hardly brain-dead. sprintf() cannot be implemented safely
> as it has no idea how big the buffer is. Memory overruns are an infamous
> problem in C, and using sprintf() in 2026 is madness IMNSHO.
>
> OpenBSD has this same warning as macOS BTW.



Well, at the end of the day macos is in fact a BSD based system ;)

About memory safety, if we know the buffer has enough memory, it’s okay. I
completely agree with Branko. I believe in that snippet of code, the
function is used to format a number which realistically could never exceed
like 16 bytes.

I wouldn’t say you should avoid a specific function just because you don’t
like it or somebody on the internet says so. It’s fine whenever you know
what you’re doing.

Then, some day it leads to Rust rewrites…


>

Re: svn commit: r1934788 - in subversion/trunk/subversion: svn tests/libsvn_subr

Posted by Branko Čibej <br...@apache.org>.
On 1. 6. 2026 22:55, Sean McBride wrote:
> On 1 Jun 2026, at 16:46, Branko Čibej wrote:
>
>> I prefer to just silence the brain-dead warning...
> The warning is hardly brain-dead. sprintf() cannot be implemented safely as it has no idea how big the buffer is. Memory overruns are an infamous problem in C, and using sprintf() in 2026 is madness IMNSHO.

Your opinion is noted. Whether or not sprintf() can be implemented 
safely is not the issue. It can be and is used safely in this instance.

> OpenBSD has this same warning as macOS BTW.

Why not deprecate all of pre-C99 <string.h> while we're at it? Pretty 
much all of it is impossible to implement safely.

-- Brane

Re: svn commit: r1934788 - in subversion/trunk/subversion: svn tests/libsvn_subr

Posted by Sean McBride <se...@rogue-research.com>.
On 1 Jun 2026, at 16:46, Branko Čibej wrote:

> I prefer to just silence the brain-dead warning...

The warning is hardly brain-dead. sprintf() cannot be implemented safely as it has no idea how big the buffer is. Memory overruns are an infamous problem in C, and using sprintf() in 2026 is madness IMNSHO.

OpenBSD has this same warning as macOS BTW.

Re: svn commit: r1934788 - in subversion/trunk/subversion: svn tests/libsvn_subr

Posted by Branko Čibej <br...@apache.org>.
On 1. 6. 2026 22:30, Nathan Hartman wrote:
> On Mon, Jun 1, 2026 at 3:37 PM Sean McBride<se...@rogue-research.com> wrote:
>> On 31 May 2026, at 13:38, Branko Čibej wrote:
>>
>> We can't use snprintf() because it's C99. Subversion is written in C90.
>>
>> You could always do:
>>
>> #ifdef APPLE || (STDC_VERSION >= 199901L)
>> snprintf(...)
>> #else
>> sprintf(...)
>> #endif
>>
>> I would not be surprised if Apple removes sprintf() one day, this way you'd be ready.
>
> You could even remove the APPLE from that condition and just check for
> STDC_VERSION.
>
> We are implemented in C90 but nothing stops someone from building with
> a later standard.

Or we could create a configure-time check – in two build systems, no 
less – if snprintf() is available, and write a wrapper that selects the 
right function. Or go way overboard in some other way, for example, by 
extracting the number separator from LC_NUMERIC from locale info and 
completely differently on Windows. All for that one usage in our core code.

I prefer to just silence the brain-dead warning and leave code that's 
been running just fine for the last 8 years alone. We do the same for 
MSVC with _CRT_SECURE_NO_DEPRECATE & Co. and at least Microsoft gives us 
just the one knob to turn those warnings off.

-- Brane

Re: svn commit: r1934788 - in subversion/trunk/subversion: svn tests/libsvn_subr

Posted by Nathan Hartman <ha...@gmail.com>.
On Mon, Jun 1, 2026 at 3:37 PM Sean McBride <se...@rogue-research.com> wrote:
>
> On 31 May 2026, at 13:38, Branko Čibej wrote:
>
> We can't use snprintf() because it's C99. Subversion is written in C90.
>
> You could always do:
>
> #ifdef APPLE || (STDC_VERSION >= 199901L)
> snprintf(...)
> #else
> sprintf(...)
> #endif
>
> I would not be surprised if Apple removes sprintf() one day, this way you'd be ready.


You could even remove the APPLE from that condition and just check for
STDC_VERSION.

We are implemented in C90 but nothing stops someone from building with
a later standard.

Nathan