From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#8545: issues with recent doprnt-related changes Date: Tue, 26 Apr 2011 13:25:21 -0700 Organization: UCLA Computer Science Department Message-ID: <4DB72A31.8040203@cs.ucla.edu> References: <4DB50AB9.6060100@cs.ucla.edu> <83tydmaeo3.fsf@gnu.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1303850285 14793 80.91.229.12 (26 Apr 2011 20:38:05 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 26 Apr 2011 20:38:05 +0000 (UTC) Cc: 8545@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Apr 26 22:38:01 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QEp1E-0005ZL-H1 for geb-bug-gnu-emacs@m.gmane.org; Tue, 26 Apr 2011 22:38:00 +0200 Original-Received: from localhost ([::1]:50093 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QEp1E-0008KK-0T for geb-bug-gnu-emacs@m.gmane.org; Tue, 26 Apr 2011 16:38:00 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:41417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QEp1B-0008KD-6y for bug-gnu-emacs@gnu.org; Tue, 26 Apr 2011 16:37:58 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QEp19-0005De-CK for bug-gnu-emacs@gnu.org; Tue, 26 Apr 2011 16:37:57 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:38209) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QEp19-0005Da-AH for bug-gnu-emacs@gnu.org; Tue, 26 Apr 2011 16:37:55 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QEope-0000je-9y; Tue, 26 Apr 2011 16:26:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Paul Eggert Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 26 Apr 2011 20:26:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8545 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 8545-submit@debbugs.gnu.org id=B8545.13038495312787 (code B ref 8545); Tue, 26 Apr 2011 20:26:02 +0000 Original-Received: (at 8545) by debbugs.gnu.org; 26 Apr 2011 20:25:31 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QEop9-0000it-8r for submit@debbugs.gnu.org; Tue, 26 Apr 2011 16:25:31 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QEop5-0000ie-Us for 8545@debbugs.gnu.org; Tue, 26 Apr 2011 16:25:28 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 66A4839E8100; Tue, 26 Apr 2011 13:25:22 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IAvBaHlmTiqW; Tue, 26 Apr 2011 13:25:21 -0700 (PDT) Original-Received: from [131.179.64.200] (Penguin.CS.UCLA.EDU [131.179.64.200]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id DF7B139E80FA; Tue, 26 Apr 2011 13:25:21 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.15) Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Thunderbird/3.1.9 In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Tue, 26 Apr 2011 16:26:02 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 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.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:46020 Archived-At: On 04/25/11 06:37, Stefan Monnier wrote: >> AFAIU, the >> > preference to use signed is for those values that come from Lisp or go >> > back to the Lisp level, which is not the case here. > Mixing the two is what I find problematic, so if it's size_t all the > way, that's OK. Sorry, but I don't see the general principle. Earlier, it was thought that emacs_write should return a signed value, because there's code like (emacs_write (...) != n) in fileio.c, where 'n' is signed, and signed-versus-unsigned comparison is problematic. I can certainly understand this point of view. With doprnt returning size_t, though, we still have this problem. In eval.c's verror we see this: size_t size_max = min (MOST_POSITIVE_FIXNUM, min (INT_MAX, SIZE_MAX - 1)) + 1; size_t used = ..., size = ...; ... while (1) { ... if (used < size - 1) break; if (size <= size_max / 2) size *= 2; else if (size < size_max) size = size_max; else break; /* and leave the message truncated */ ... } Here, the code is carefully comparing a signed value MOST_POSITIVE_FIXNUM to a possibly-different-width unsigned value SIZE_MAX - 1, storing the result into an unsigned variable, and using that unsigned variable. This comparison happens to be safe, but one has to stare at it a bit to make sure that the unsigned-versus-signed comparison isn't bogus. Why is this unsigned-versus-signed comparison OK, but the one with emacs_write problematic? I'm not saying this to be difficult: I'm just trying to understand the general principle here. I thought the point of preferring signed was so that we didn't have to worry about stuff like the above. Also I assumed the idea is that one should be able to compile GCC with -ftrapv and catch overflow errors. But if the above code is OK as-is, then clearly I'm misunderstanding the overall goal here.