From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#57211: 29.0.50; generate-new-buffer-name sprintf format overflow warning Date: Sun, 14 Aug 2022 13:54:08 -0700 Organization: UCLA Computer Science Department Message-ID: <9bd9ae82-8525-1d32-c4a1-5daaf909609a@cs.ucla.edu> References: <87ilmulqh0.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------cHBEzP78i3PWcCbbqqfXVX0u" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28017"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Cc: 57211-done@debbugs.gnu.org To: "Basil L. Contovounesios" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Aug 14 22:55:13 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oNKdd-00073j-2m for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Aug 2022 22:55:13 +0200 Original-Received: from localhost ([::1]:35932 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oNKdb-0004CN-Mg for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 14 Aug 2022 16:55:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:36728) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oNKdS-00049L-FX for bug-gnu-emacs@gnu.org; Sun, 14 Aug 2022 16:55:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:50233) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oNKdS-0006OF-5Q for bug-gnu-emacs@gnu.org; Sun, 14 Aug 2022 16:55:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oNKdS-0003xR-0g for bug-gnu-emacs@gnu.org; Sun, 14 Aug 2022 16:55:02 -0400 Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Sun, 14 Aug 2022 20:55:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 57211 X-GNU-PR-Package: emacs Mail-Followup-To: 57211@debbugs.gnu.org, eggert@cs.ucla.edu, contovob@tcd.ie Original-Received: via spool by 57211-done@debbugs.gnu.org id=D57211.166051045715152 (code D ref 57211); Sun, 14 Aug 2022 20:55:01 +0000 Original-Received: (at 57211-done) by debbugs.gnu.org; 14 Aug 2022 20:54:17 +0000 Original-Received: from localhost ([127.0.0.1]:39980 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oNKcj-0003wJ-DV for submit@debbugs.gnu.org; Sun, 14 Aug 2022 16:54:17 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:55824) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oNKch-0003w5-Hg for 57211-done@debbugs.gnu.org; Sun, 14 Aug 2022 16:54:16 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id BD60F16010A; Sun, 14 Aug 2022 13:54:09 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id FCuGh5l7Pv8m; Sun, 14 Aug 2022 13:54:08 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id C137316010B; Sun, 14 Aug 2022 13:54:08 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id cGVawmk0Eirm; Sun, 14 Aug 2022 13:54:08 -0700 (PDT) Original-Received: from [192.168.1.9] (cpe-172-91-119-151.socal.res.rr.com [172.91.119.151]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 908B516010A; Sun, 14 Aug 2022 13:54:08 -0700 (PDT) Content-Language: en-US In-Reply-To: <87ilmulqh0.fsf@tcd.ie> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:239701 Archived-At: This is a multi-part message in MIME format. --------------cHBEzP78i3PWcCbbqqfXVX0u Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 8/14/22 09:50, Basil L. Contovounesios wrote: > Can the upper bound 9 ever be achieved? If so, how? If not, is this a > GCC bug? Either way, is there a way to pacify the warning? It can't be achieved, and it's arguably a GCC bug. I installed the attached to pacify GCC. > int i = r % 1000000; > > can the result of % ever exceed INT_MAX? No. On 8/14/22 11:59, Matt Armstrong wrote: > Gcc doesn't know that get_random() returns only non-negative numbers, > and the eassume() call doesn't seem to be enough to convince gcc this > fact, or gcc does not infer i is also non-negative. It's worse than that. Even if you add 'eassume (0 <= i && i < 1000000);" GCC still doesn't assume that the sprintf is in range. > Personally, I'd change this code to use a buffer > > INT_BUFSIZE_BOUND(int) + sizeof "-" The problem with overallocating buffers is not the memory loss (it's trivial, as you say), it's that later readers like me will wonder why the buffer is being overallocated, which is maintenance overhead. I installed the attached to pacify GCC while also attempting to not entirely mystify later readers. --------------cHBEzP78i3PWcCbbqqfXVX0u Content-Type: text/x-patch; charset=UTF-8; name="0001-Work-around-Bug-57211.patch" Content-Disposition: attachment; filename="0001-Work-around-Bug-57211.patch" Content-Transfer-Encoding: base64 RnJvbSAyMzU2MWY5NjY1NjA5YmNiNGNiZTg5YTk5M2E3MGVlY2NiZWM2MDBlIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBQYXVsIEVnZ2VydCA8ZWdnZXJ0QGNzLnVjbGEuZWR1 PgpEYXRlOiBTdW4sIDE0IEF1ZyAyMDIyIDEzOjQ4OjExIC0wNzAwClN1YmplY3Q6IFtQQVRD SF0gV29yayBhcm91bmQgQnVnIzU3MjExCgoqIHNyYy9idWZmZXIuYyAoRmdlbmVyYXRlX25l d19idWZmZXJfbmFtZSk6IEFsbG9jYXRlIGEgYmlnZ2VyIGJ1ZmZlci4KLS0tCiBzcmMvYnVm ZmVyLmMgfCAzICsrLQogMSBmaWxlIGNoYW5nZWQsIDIgaW5zZXJ0aW9ucygrKSwgMSBkZWxl dGlvbigtKQoKZGlmZiAtLWdpdCBhL3NyYy9idWZmZXIuYyBiL3NyYy9idWZmZXIuYwppbmRl eCA2YWI1MTZkNWY1Li45ODA2NmEyZWI2IDEwMDY0NAotLS0gYS9zcmMvYnVmZmVyLmMKKysr IGIvc3JjL2J1ZmZlci5jCkBAIC0xMTYwLDcgKzExNjAsOCBAQCBERUZVTiAoImdlbmVyYXRl LW5ldy1idWZmZXItbmFtZSIsIEZnZW5lcmF0ZV9uZXdfYnVmZmVyX25hbWUsCiAgICAgZ2Vu YmFzZSA9IG5hbWU7CiAgIGVsc2UKICAgICB7Ci0gICAgICBjaGFyIG51bWJlcltzaXplb2Yg Ii05OTk5OTkiXTsKKyAgICAgIGVudW0geyBidWdfNTI3MTEgPSB0cnVlIH07ICAvKiBodHRw czovL2J1Z3MuZ251Lm9yZy81NzIxMSAqLworICAgICAgY2hhciBudW1iZXJbYnVnXzUyNzEx ID8gSU5UX0JVRlNJWkVfQk9VTkQgKGludCkgKyAxIDogc2l6ZW9mICItOTk5OTk5Il07CiAg ICAgICBFTUFDU19JTlQgciA9IGdldF9yYW5kb20gKCk7CiAgICAgICBlYXNzdW1lICgwIDw9 IHIpOwogICAgICAgaW50IGkgPSByICUgMTAwMDAwMDsKLS0gCjIuMzQuMQoK --------------cHBEzP78i3PWcCbbqqfXVX0u--