From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: oops? read/write vs type of length parameter Date: Mon, 11 Apr 2011 05:44:17 -0400 Message-ID: References: <87wrj1jhfc.fsf@rho.meyering.net> Reply-To: Eli Zaretskii NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1302515077 20797 80.91.229.12 (11 Apr 2011 09:44:37 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 11 Apr 2011 09:44:37 +0000 (UTC) Cc: emacs-devel@gnu.org To: Jim Meyering Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Apr 11 11:44:28 2011 Return-path: Envelope-to: ged-emacs-devel@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 1Q9DfU-0000Pq-JO for ged-emacs-devel@m.gmane.org; Mon, 11 Apr 2011 11:44:24 +0200 Original-Received: from localhost ([127.0.0.1]:60739 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q9DfT-0000xD-GO for ged-emacs-devel@m.gmane.org; Mon, 11 Apr 2011 05:44:23 -0400 Original-Received: from [140.186.70.92] (port=53041 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q9DfO-0000uR-QJ for emacs-devel@gnu.org; Mon, 11 Apr 2011 05:44:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q9DfN-0005M0-8w for emacs-devel@gnu.org; Mon, 11 Apr 2011 05:44:18 -0400 Original-Received: from fencepost.gnu.org ([140.186.70.10]:36485) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q9DfN-0005Lw-4j for emacs-devel@gnu.org; Mon, 11 Apr 2011 05:44:17 -0400 Original-Received: from eliz by fencepost.gnu.org with local (Exim 4.71) (envelope-from ) id 1Q9DfN-00007M-08; Mon, 11 Apr 2011 05:44:17 -0400 In-reply-to: <87wrj1jhfc.fsf@rho.meyering.net> (message from Jim Meyering on Mon, 11 Apr 2011 10:55:35 +0200) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.10 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:138378 Archived-At: > From: Jim Meyering > Date: Mon, 11 Apr 2011 10:55:35 +0200 > Cc: Eli Zaretskii > > In http://bzr.savannah.gnu.org/lh/emacs/trunk/revision/103883 > you adjusted the signatures of emacs_read and emacs_write. > > - extern int emacs_read (int, char *, unsigned int); > - extern int emacs_write (int, const char *, unsigned int); > + extern ssize_t emacs_read (int, char *, ssize_t); > + extern ssize_t emacs_write (int, const char *, ssize_t); Yes, that's part of my on-going effort to allow editing of files larger than 2GB. With that revision, I can finally visit such a large file, modify it, and save it to disk :-) > It's good to see that you corrected the return type to be wider > (ssize_t) and still signed, just like "int". That's what its callers expect: the return value can be positive or negative. > However, did you really intend to make the buffer length parameters signed? > I would have expected those to be of type size_t, not ssize_t. We call these functions with an argument of type EMACS_INT, which can be negative. I don't want it to wind up as a large positive value inside these functions, I'd rather the functions fail instead. Note that emacs_write is careful enough to check the sign of that argument, and if we want a similar guard in emacs_read, we can easily add that. Is there a problem with that?