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#8435: misuse of error ("...%d...", ...) on 64-bit hosts Date: Wed, 06 Apr 2011 12:59:09 -0700 Organization: UCLA Computer Science Department Message-ID: <4D9CC60D.2090301@cs.ucla.edu> 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 1302120449 19903 80.91.229.12 (6 Apr 2011 20:07:29 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 6 Apr 2011 20:07:29 +0000 (UTC) To: 8435@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Wed Apr 06 22:07:25 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q7Z0e-0001tE-SB for geb-bug-gnu-emacs@m.gmane.org; Wed, 06 Apr 2011 22:07:25 +0200 Original-Received: from localhost ([127.0.0.1]:50691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q7Z0e-0000RS-8j for geb-bug-gnu-emacs@m.gmane.org; Wed, 06 Apr 2011 16:07:24 -0400 Original-Received: from [140.186.70.92] (port=35096 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q7Z0Z-0000RK-4R for bug-gnu-emacs@gnu.org; Wed, 06 Apr 2011 16:07:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q7Z0Y-0005yQ-8N for bug-gnu-emacs@gnu.org; Wed, 06 Apr 2011 16:07:18 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:47255) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q7Z0Y-0005yM-6o for bug-gnu-emacs@gnu.org; Wed, 06 Apr 2011 16:07:18 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Q7YtX-0002cm-59; Wed, 06 Apr 2011 16:00:03 -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: Wed, 06 Apr 2011 20:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 8435 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.130211997010029 (code B ref -1); Wed, 06 Apr 2011 20:00:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 6 Apr 2011 19:59:30 +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 1Q7Ysz-0002bh-St for submit@debbugs.gnu.org; Wed, 06 Apr 2011 15:59:30 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Q7Ysx-0002bW-Jz for submit@debbugs.gnu.org; Wed, 06 Apr 2011 15:59:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q7Ysr-0003fo-MF for submit@debbugs.gnu.org; Wed, 06 Apr 2011 15:59:22 -0400 Original-Received: from lists.gnu.org ([199.232.76.165]:54999) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q7Ysr-0003fk-K1 for submit@debbugs.gnu.org; Wed, 06 Apr 2011 15:59:21 -0400 Original-Received: from [140.186.70.92] (port=51976 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q7Ysq-0004wP-C3 for bug-gnu-emacs@gnu.org; Wed, 06 Apr 2011 15:59:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q7Ysp-0003fA-I0 for bug-gnu-emacs@gnu.org; Wed, 06 Apr 2011 15:59:20 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:60983) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q7Ysp-0003cd-8v for bug-gnu-emacs@gnu.org; Wed, 06 Apr 2011 15:59:19 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 4384E39E80E0 for ; Wed, 6 Apr 2011 12:59:10 -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 d7qYB6xokV4u for ; Wed, 6 Apr 2011 12:59:09 -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 C70E339E80DB for ; Wed, 6 Apr 2011 12:59:09 -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 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Wed, 06 Apr 2011 16:00:03 -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: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:45667 Archived-At: In the Emacs trunk, src/dispnew.c contains this: error ("Device %d is not a termcap terminal device", t->id); t->id is of type 'int', but the "error" routine formats %d as if it were of type EMACS_INT. This works on a typical 32-bit machine, but on a 64-bit machine these two types have different representations, and the above call relies on undefined behavior: it might work and it might not. The above bug can easily be fixed by casting t->id to EMACS_INT, but other instances of the problem are not so easy. For example, src/term.c has this: maybe_fatal (must_succeed, terminal, "Screen size %dx%d is too small", "Screen size %dx%d is too small", FrameCols (tty), FrameRows (tty)); where FrameCols and FrameRows return 'int'. Here, if MUST_SUCCEED is true, maybe_fatal calls 'printf' and works; but if MUST_SUCCEED is false, maybe_fatal calls 'error' and might not work on a 64-bit machine. I found these bugs by code inspection, and expect that there are others like them. Part of the problem is that it's confusing that 'error' treats format strings differently from 'printf'. And partly the problem is that there is currently no reliable way to catch common programming mistakes like this. I plan to fix this problem systematically, as follows. * Provide a convenient way to format EMACS_INT values using printf-like functions. * Change 'error' and similar functions so that they use printf-compatible format strings, and change their callers to format EMACS_INT values accordingly. * Mark 'error'-like functions with ATTRIBUTE_FORMAT_PRINTF, so that we can easily find other bugs like the above.