From 9587a89da041d3848bd6b639e836d70cb40b4bd6 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 15 Apr 2011 01:22:34 -0700 Subject: [PATCH] emacs_write: Accept and return EMACS_INT for sizes. --- src/ChangeLog | 25 +++++++++++-------------- src/gnutls.c | 10 +++++----- src/gnutls.h | 8 ++++---- src/lisp.h | 4 ++-- src/sysdep.c | 10 +++++----- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 8589bb8a9f0..3025e459fd0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,24 +1,21 @@ 2011-04-15 Paul Eggert - * sysdep.c (MAX_RW_COUNT): New macro, to work around kernel bugs. - (emacs_read, emacs_write): Use it. - - * process.c (send_process): Count partial writes as successes. - See http://lists.gnu.org/archive/html/emacs-devel/2011-04/msg00483.html - - emacs_write: Return size_t, not ssize_t, to avoid overflow issues. - * gnutls.c, gnutls.h (emacs_gnutls_write): Return size_t, not ssize_t. - * sysdep.c, lisp.h (emacs_write): Likewise. - Without the above change, emacs_gnutls_write and emacs_write had - undefined behavior and would typically mistakenly report an error - when writing a buffer whose size exceeds SSIZE_MAX. + emacs_write: Accept and return EMACS_INT for sizes. + See http://lists.gnu.org/archive/html/emacs-devel/2011-04/msg00514.html + et seq. + * gnutls.c, gnutls.h (emacs_gnutls_read, emacs_gnutls_write): + Accept and return EMACS_INT. + (emacs_gnutls_write): Return the number of bytes written on + partial writes. + * sysdep.c, lisp.h (emacs_read, emacs_write): Likewise. (emacs_read, emacs_write): Remove check for negative size, as the Emacs source code has been audited now. - (emacs_write): Adjust to new signature, making the code look more - like that of emacs_gnutls_write. + * sysdep.c (MAX_RW_COUNT): New macro, to work around kernel bugs. + (emacs_read, emacs_write): Use it. * process.c (send_process): Adjust to the new signatures of emacs_write and emacs_gnutls_write. Do not attempt to store a byte offset into an 'int'; it might overflow. + See http://lists.gnu.org/archive/html/emacs-devel/2011-04/msg00483.html * sound.c: Don't assume sizes fit in 'int'. (struct sound_device.period_size, alsa_period_size): diff --git a/src/gnutls.c b/src/gnutls.c index 2974f048459..d7328e114c7 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -70,12 +70,12 @@ emacs_gnutls_handshake (struct Lisp_Process *proc) } } -size_t +EMACS_INT emacs_gnutls_write (int fildes, struct Lisp_Process *proc, const char *buf, - size_t nbyte) + EMACS_INT nbyte) { ssize_t rtnval; - size_t bytes_written; + EMACS_INT bytes_written; gnutls_session_t state = proc->gnutls_state; if (proc->gnutls_initstage != GNUTLS_STAGE_READY) { @@ -110,9 +110,9 @@ emacs_gnutls_write (int fildes, struct Lisp_Process *proc, const char *buf, return (bytes_written); } -ssize_t +EMACS_INT emacs_gnutls_read (int fildes, struct Lisp_Process *proc, char *buf, - size_t nbyte) + EMACS_INT nbyte) { ssize_t rtnval; gnutls_session_t state = proc->gnutls_state; diff --git a/src/gnutls.h b/src/gnutls.h index 11f681f9c7b..5240d94c2ad 100644 --- a/src/gnutls.h +++ b/src/gnutls.h @@ -50,12 +50,12 @@ typedef enum #define GNUTLS_LOG2(level, max, string, extra) if (level <= max) { gnutls_log_function2 (level, "(Emacs) " string, extra); } -size_t +EMACS_INT emacs_gnutls_write (int fildes, struct Lisp_Process *proc, const char *buf, - size_t nbyte); -ssize_t + EMACS_INT nbyte); +EMACS_INT emacs_gnutls_read (int fildes, struct Lisp_Process *proc, char *buf, - size_t nbyte); + EMACS_INT nbyte); extern void syms_of_gnutls (void); diff --git a/src/lisp.h b/src/lisp.h index 3e5d1fcc695..581835dd32b 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3317,8 +3317,8 @@ extern long get_random (void); extern void seed_random (long); extern int emacs_open (const char *, int, int); extern int emacs_close (int); -extern ssize_t emacs_read (int, char *, size_t); -extern size_t emacs_write (int, const char *, size_t); +extern EMACS_INT emacs_read (int, char *, EMACS_INT); +extern EMACS_INT emacs_write (int, const char *, EMACS_INT); enum { READLINK_BUFSIZE = 1024 }; extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]); #ifndef HAVE_MEMSET diff --git a/src/sysdep.c b/src/sysdep.c index 06fbd2b7d0f..6b6e3e9e791 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1839,8 +1839,8 @@ emacs_close (int fd) /* Read from FILEDESC to a buffer BUF with size NBYTE, retrying if interrupted. Return the number of bytes read, which might be less than NBYTE. On error, set errno and return -1. */ -ssize_t -emacs_read (int fildes, char *buf, size_t nbyte) +EMACS_INT +emacs_read (int fildes, char *buf, EMACS_INT nbyte) { register ssize_t rtnval; @@ -1853,11 +1853,11 @@ emacs_read (int fildes, char *buf, size_t nbyte) /* Write to FILEDES from a buffer BUF with size NBYTE, retrying if interrupted or if a partial write occurs. Return the number of bytes written, setting errno if this is less than NBYTE. */ -size_t -emacs_write (int fildes, const char *buf, size_t nbyte) +EMACS_INT +emacs_write (int fildes, const char *buf, EMACS_INT nbyte) { ssize_t rtnval; - size_t bytes_written; + EMACS_INT bytes_written; bytes_written = 0; -- 2.39.2