unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Stefan Kangas <stefankangas@gmail.com>, rms@gnu.org
Cc: gerd.moellmann@gmail.com, jacob.fai@gmail.com, 58966@debbugs.gnu.org
Subject: bug#58966: [Trunk] Xcode 14.1+ (and macOS 13.0+) deprecate sprintf()
Date: Sat, 5 Nov 2022 13:00:25 -0700	[thread overview]
Message-ID: <be1f3a8d-1f14-00d7-b69e-2c3b30dd78f1@cs.ucla.edu> (raw)
In-Reply-To: <CADwFkmkRnLC+whVHLsrV=10qr2u1e7OouHpG-FNj=vgO-sDBSw@mail.gmail.com>

On 2022-11-05 09:26, Stefan Kangas wrote:
> snprintf is part of the C99 standard, so I think we can always rely on
> it being there.  Switching sounds like a good idea.

sprintf is also part of the C99 (and C17 and C23) standards, so "it's in 
the standard" does not mean we need to switch away from sprintf.

While we're on the topic: sprintf and snprintf both have serious design 
flaws, in that they cannot generate output longer than INT_MAX bytes, 
and this contradicts the GNU design philosophy to avoid arbitrary 
limits. Instead, code that needs low level formatting should use Emacs's 
own esprintf family of functions, which don't have the INT_MAX limit. 
(Often it's better for code to use Fformat etc. and generate a Lisp 
string, which doesn't have that limit either.)

Admittedly we haven't always been good about this, as sprintf/snprintf 
are standard and are tempting to use. It might be a good idea, though, 
for someone to go through the code and see if there are any 
INT_MAX-related bugs lurking in Emacs now due to its use of sprintf 
and/or snprintf, and replace these calls with something better.


On 2022-11-04 20:12, Richard Stallman wrote:
 > We could switch to snprintf, and define snprintf to call sprintf
 > in systems where snprintf isn't available.

That wouldn't that easy to do, and would make code more awkward and slow 
it down a bit. The current 3-line change to configure.ac is much 
simpler. It's pretty implausible that Apple will make sprintf go away 
entirely - and if Apple is foolish enough to do so, there are simple 
workarounds for that that don't involve messing with our legacy code.

> It is possible to verify
> that sprintf did not overwrite the buffer.

Sorry, I don't know what this comment is trying to say.

In my experience, with a debugging runtime sprintf is better than 
snprintf, as sprintf reliably reports bugs whereas snprintf silently 
truncates and continues with hard-to-debug behavior occuring later. Of 
course with traditional non-debugging runtimes one loses with sprintf, 
but in practice it's a tradeoff often worth making.







  reply	other threads:[~2022-11-05 20:00 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-02 13:56 bug#58966: [Trunk] Xcode 14.1+ (and macOS 13.0+) deprecate sprintf() Jacob Faibussowitsch
2022-11-03  5:56 ` Gerd Möllmann
2022-11-03  8:16   ` Eli Zaretskii
2022-11-03  9:00     ` Gerd Möllmann
2022-11-03  9:15       ` Eli Zaretskii
2022-11-03  9:36         ` Gerd Möllmann
2022-11-03 14:40           ` Jacob Faibussowitsch
2022-11-03 14:43             ` Gerd Möllmann
2022-11-03 14:48               ` Jacob Faibussowitsch
2022-11-03 15:22                 ` Gerd Möllmann
2022-11-03 15:30                   ` Jacob Faibussowitsch
2022-11-03 16:15                     ` Gerd Möllmann
2022-11-03 16:19                       ` Gerd Möllmann
2022-11-03 18:30 ` Paul Eggert
2022-11-04 21:07   ` Jacob Faibussowitsch
2022-11-05  3:12   ` Richard Stallman
2022-11-05 16:26     ` Stefan Kangas
2022-11-05 20:00       ` Paul Eggert [this message]
2022-11-07  7:46         ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=be1f3a8d-1f14-00d7-b69e-2c3b30dd78f1@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=58966@debbugs.gnu.org \
    --cc=gerd.moellmann@gmail.com \
    --cc=jacob.fai@gmail.com \
    --cc=rms@gnu.org \
    --cc=stefankangas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).