From 3e047f51d5ad36df46d553d1090e28f546af9382 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 12 Apr 2011 20:22:40 -0700 Subject: [PATCH 1/8] * sound.c: Don't assume sizes fit in 'int'. (struct sound_device.period_size, alsa_period_size): Return size_t, not int. (struct sound_device.write, vox_write, alsa_write): Accept size_t, not int. (wav_play, au_play): Use size_t to store sizes, and ssize_t to record read return values. --- src/ChangeLog | 10 ++++++++++ src/sound.c | 27 +++++++++++++-------------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 211625ee446..6b0e575e36d 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,13 @@ +2011-04-13 Paul Eggert + + * sound.c: Don't assume sizes fit in 'int'. + (struct sound_device.period_size, alsa_period_size): + Return size_t, not int. + (struct sound_device.write, vox_write, alsa_write): + Accept size_t, not int. + (wav_play, au_play): Use size_t to store sizes, and ssize_t to + record read return values. + 2011-04-12 Andreas Schwab * charset.c (Fclear_charset_maps): Use xfree instead of free. diff --git a/src/sound.c b/src/sound.c index 7d7317e71b3..c0741f27ff6 100644 --- a/src/sound.c +++ b/src/sound.c @@ -235,11 +235,11 @@ struct sound_device /* Return a preferred data size in bytes to be sent to write (below) each time. 2048 is used if this is NULL. */ - int (* period_size) (struct sound_device *sd); + size_t (* period_size) (struct sound_device *sd); /* Write NYBTES bytes from BUFFER to device SD. */ void (* write) (struct sound_device *sd, const char *buffer, - int nbytes); + size_t nbytes); /* A place for devices to store additional data. */ void *data; @@ -291,7 +291,7 @@ static void vox_configure (struct sound_device *); static void vox_close (struct sound_device *sd); static void vox_choose_format (struct sound_device *, struct sound *); static int vox_init (struct sound_device *); -static void vox_write (struct sound_device *, const char *, int); +static void vox_write (struct sound_device *, const char *, size_t); static void find_sound_type (struct sound *); static u_int32_t le2hl (u_int32_t); static u_int16_t le2hs (u_int16_t); @@ -600,9 +600,9 @@ wav_play (struct sound *s, struct sound_device *sd) else { char *buffer; - int nbytes = 0; - int blksize = sd->period_size ? sd->period_size (sd) : 2048; - int data_left = header->data_length; + ssize_t nbytes = 0; + size_t blksize = sd->period_size ? sd->period_size (sd) : 2048; + size_t data_left = header->data_length; buffer = (char *) alloca (blksize); lseek (s->fd, sizeof *header, SEEK_SET); @@ -690,9 +690,9 @@ au_play (struct sound *s, struct sound_device *sd) SBYTES (s->data) - header->data_offset); else { - int blksize = sd->period_size ? sd->period_size (sd) : 2048; + size_t blksize = sd->period_size ? sd->period_size (sd) : 2048; char *buffer; - int nbytes; + ssize_t nbytes; /* Seek */ lseek (s->fd, header->data_offset, SEEK_SET); @@ -895,10 +895,9 @@ vox_init (struct sound_device *sd) /* Write NBYTES bytes from BUFFER to device SD. */ static void -vox_write (struct sound_device *sd, const char *buffer, int nbytes) +vox_write (struct sound_device *sd, const char *buffer, size_t nbytes) { - ssize_t nwritten = emacs_write (sd->fd, buffer, nbytes); - if (nwritten < 0) + if (emacs_write (sd->fd, buffer, nbytes) != nbytes) sound_perror ("Error writing to sound device"); } @@ -953,7 +952,7 @@ alsa_open (struct sound_device *sd) alsa_sound_perror (file, err); } -static int +static size_t alsa_period_size (struct sound_device *sd) { struct alsa_params *p = (struct alsa_params *) sd->data; @@ -1156,13 +1155,13 @@ alsa_choose_format (struct sound_device *sd, struct sound *s) /* Write NBYTES bytes from BUFFER to device SD. */ static void -alsa_write (struct sound_device *sd, const char *buffer, int nbytes) +alsa_write (struct sound_device *sd, const char *buffer, size_t nbytes) { struct alsa_params *p = (struct alsa_params *) sd->data; /* The the third parameter to snd_pcm_writei is frames, not bytes. */ int fact = snd_pcm_format_size (sd->format, 1) * sd->channels; - int nwritten = 0; + size_t nwritten = 0; int err; while (nwritten < nbytes) From 273a5f82856e545365fbf9278bd739cb6c5aa35e Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 12 Apr 2011 22:02:54 -0700 Subject: [PATCH 2/8] 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_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. * 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. --- src/ChangeLog | 14 ++++++++++++++ src/gnutls.c | 6 +++--- src/gnutls.h | 2 +- src/lisp.h | 2 +- src/process.c | 24 +++++++++++++----------- src/sysdep.c | 30 +++++++++++++----------------- 6 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6b0e575e36d..73d27f26d45 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,19 @@ 2011-04-13 Paul Eggert + 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_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. + * 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. + * sound.c: Don't assume sizes fit in 'int'. (struct sound_device.period_size, alsa_period_size): Return size_t, not int. diff --git a/src/gnutls.c b/src/gnutls.c index d9e4dcec15a..2974f048459 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -70,7 +70,7 @@ emacs_gnutls_handshake (struct Lisp_Process *proc) } } -ssize_t +size_t emacs_gnutls_write (int fildes, struct Lisp_Process *proc, const char *buf, size_t nbyte) { @@ -85,7 +85,7 @@ emacs_gnutls_write (int fildes, struct Lisp_Process *proc, const char *buf, #ifdef EAGAIN errno = EAGAIN; #endif - return -1; + return 0; } bytes_written = 0; @@ -99,7 +99,7 @@ emacs_gnutls_write (int fildes, struct Lisp_Process *proc, const char *buf, if (rtnval == GNUTLS_E_AGAIN || rtnval == GNUTLS_E_INTERRUPTED) continue; else - return (bytes_written ? bytes_written : -1); + break; } buf += rtnval; diff --git a/src/gnutls.h b/src/gnutls.h index b39131b6236..11f681f9c7b 100644 --- a/src/gnutls.h +++ b/src/gnutls.h @@ -50,7 +50,7 @@ typedef enum #define GNUTLS_LOG2(level, max, string, extra) if (level <= max) { gnutls_log_function2 (level, "(Emacs) " string, extra); } -ssize_t +size_t emacs_gnutls_write (int fildes, struct Lisp_Process *proc, const char *buf, size_t nbyte); ssize_t diff --git a/src/lisp.h b/src/lisp.h index 080b2693a41..ae8f3c793c5 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -3347,7 +3347,7 @@ 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 ssize_t emacs_write (int, const char *, size_t); +extern size_t emacs_write (int, const char *, size_t); enum { READLINK_BUFSIZE = 1024 }; extern char *emacs_readlink (const char *, char [READLINK_BUFSIZE]); #ifndef HAVE_MEMSET diff --git a/src/process.c b/src/process.c index 624610069d8..2eed7b4654f 100644 --- a/src/process.c +++ b/src/process.c @@ -5367,6 +5367,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, /* Send this batch, using one or more write calls. */ while (this > 0) { + size_t written = 0; int outfd = p->outfd; old_sigpipe = (void (*) (int)) signal (SIGPIPE, send_process_trap); #ifdef DATAGRAM_SOCKETS @@ -5375,7 +5376,9 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, rv = sendto (outfd, buf, this, 0, datagram_address[outfd].sa, datagram_address[outfd].len); - if (rv < 0 && errno == EMSGSIZE) + if (0 <= rv) + written = rv; + else if (errno == EMSGSIZE) { signal (SIGPIPE, old_sigpipe); report_file_error ("sending datagram", @@ -5387,12 +5390,13 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, { #ifdef HAVE_GNUTLS if (XPROCESS (proc)->gnutls_p) - rv = emacs_gnutls_write (outfd, - XPROCESS (proc), - buf, this); + written = emacs_gnutls_write (outfd, + XPROCESS (proc), + buf, this); else #endif - rv = emacs_write (outfd, buf, this); + written = emacs_write (outfd, buf, this); + rv = (written == this ? 0 : -1); #ifdef ADAPTIVE_READ_BUFFERING if (p->read_output_delay > 0 && p->adaptive_read_buffering == 1) @@ -5419,7 +5423,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, that may allow the program to finish doing output and read more. */ { - int offset = 0; + size_t offset = 0; #ifdef BROKEN_PTY_READ_AFTER_EAGAIN /* A gross hack to work around a bug in FreeBSD. @@ -5465,16 +5469,14 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, offset); else if (STRINGP (object)) buf = offset + SSDATA (object); - - rv = 0; } else /* This is a real error. */ report_file_error ("writing to process", Fcons (proc, Qnil)); } - buf += rv; - len -= rv; - this -= rv; + buf += written; + len -= written; + this -= written; } } } diff --git a/src/sysdep.c b/src/sysdep.c index d56e2a864dc..84c8d4ec0ea 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1825,41 +1825,36 @@ emacs_close (int fd) return rtnval; } +/* 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) { register ssize_t rtnval; - /* Defend against the possibility that a buggy caller passes a negative NBYTE - argument, which would be converted to a large unsigned size_t NBYTE. This - defense prevents callers from doing large writes, unfortunately. This - size restriction can be removed once we have carefully checked that there - are no such callers. */ - if ((ssize_t) nbyte < 0) - abort (); - while ((rtnval = read (fildes, buf, nbyte)) == -1 && (errno == EINTR)) QUIT; return (rtnval); } -ssize_t +/* 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) { - register ssize_t rtnval, bytes_written; - - /* Defend against negative NBYTE, as in emacs_read. */ - if ((ssize_t) nbyte < 0) - abort (); + ssize_t rtnval; + size_t bytes_written; bytes_written = 0; - while (nbyte != 0) + while (nbyte > 0) { rtnval = write (fildes, buf, nbyte); - if (rtnval == -1) + if (rtnval < 0) { if (errno == EINTR) { @@ -1871,13 +1866,14 @@ emacs_write (int fildes, const char *buf, size_t nbyte) continue; } else - return (bytes_written ? bytes_written : -1); + break; } buf += rtnval; nbyte -= rtnval; bytes_written += rtnval; } + return (bytes_written); } From 086e8c477d4342c8e718f9bb811da0b1a6e1e946 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 13 Apr 2011 12:23:45 -0700 Subject: [PATCH 3/8] * process.c (send_process): Count partial writes as successes. See http://lists.gnu.org/archive/html/emacs-devel/2011-04/msg00483.html --- src/ChangeLog | 3 +++ src/process.c | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/ChangeLog b/src/ChangeLog index 73d27f26d45..9aa58fb0884 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,8 @@ 2011-04-13 Paul Eggert + * 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. diff --git a/src/process.c b/src/process.c index 2eed7b4654f..2c3124f429c 100644 --- a/src/process.c +++ b/src/process.c @@ -5396,7 +5396,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, else #endif written = emacs_write (outfd, buf, this); - rv = (written == this ? 0 : -1); + rv = (written ? 0 : -1); #ifdef ADAPTIVE_READ_BUFFERING if (p->read_output_delay > 0 && p->adaptive_read_buffering == 1) From 1963a2e0bb07cc8dee6d27f972f93d9cfd7c6b2d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 13 Apr 2011 12:54:09 -0700 Subject: [PATCH 4/8] * sysdep.c (MAX_RW_COUNT): New macro, to work around kernel bugs. (emacs_read, emacs_write): Use it. --- src/ChangeLog | 3 +++ src/sysdep.c | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 9aa58fb0884..db387750b16 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,8 @@ 2011-04-13 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 diff --git a/src/sysdep.c b/src/sysdep.c index 84c8d4ec0ea..8d0bd3df9cc 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1825,6 +1825,17 @@ emacs_close (int fd) return rtnval; } +/* Maximum number of bytes to read or write in a single system call. + This works around a serious bug in Linux kernels before 2.6.16; see + . + It's likely to work around similar bugs in other operating systems, so do it + on all platforms. Round INT_MAX down to a page size, with the conservative + assumption that page sizes are at most 2**18 bytes (any kernel with a + page size larger than that shouldn't have the bug). */ +#ifndef MAX_RW_COUNT +#define MAX_RW_COUNT (INT_MAX >> 18 << 18) +#endif + /* 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. */ @@ -1833,7 +1844,7 @@ emacs_read (int fildes, char *buf, size_t nbyte) { register ssize_t rtnval; - while ((rtnval = read (fildes, buf, nbyte)) == -1 + while ((rtnval = read (fildes, buf, min (nbyte, MAX_RW_COUNT))) == -1 && (errno == EINTR)) QUIT; return (rtnval); @@ -1852,7 +1863,7 @@ emacs_write (int fildes, const char *buf, size_t nbyte) while (nbyte > 0) { - rtnval = write (fildes, buf, nbyte); + rtnval = write (fildes, buf, min (nbyte, MAX_RW_COUNT)); if (rtnval < 0) { From 9587a89da041d3848bd6b639e836d70cb40b4bd6 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 15 Apr 2011 01:22:34 -0700 Subject: [PATCH 5/8] 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; From 85de188188e61c9066b662bae2cc77424b74a7bd Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 15 Apr 2011 01:31:40 -0700 Subject: [PATCH 6/8] * process.c (send_process): Change another size_t to EMACS_INT. --- src/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/process.c b/src/process.c index f41cdbe5c71..6b58bc6315b 100644 --- a/src/process.c +++ b/src/process.c @@ -5368,7 +5368,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, /* Send this batch, using one or more write calls. */ while (this > 0) { - size_t written = 0; + EMACS_INT written = 0; int outfd = p->outfd; old_sigpipe = (void (*) (int)) signal (SIGPIPE, send_process_trap); #ifdef DATAGRAM_SOCKETS From 3d6c25432149acdf5c3c3eb11f4857922dab089c Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 15 Apr 2011 01:35:53 -0700 Subject: [PATCH 7/8] * process.c (send_process): Change a size_t to EMACS_INT. --- src/process.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/process.c b/src/process.c index 6b58bc6315b..c9c6ab6d4b3 100644 --- a/src/process.c +++ b/src/process.c @@ -5424,7 +5424,7 @@ send_process (volatile Lisp_Object proc, const char *volatile buf, that may allow the program to finish doing output and read more. */ { - size_t offset = 0; + EMACS_INT offset = 0; #ifdef BROKEN_PTY_READ_AFTER_EAGAIN /* A gross hack to work around a bug in FreeBSD. From a0238ccadcb6bf4eaf5caaced7d3904458a698db Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 15 Apr 2011 01:47:25 -0700 Subject: [PATCH 8/8] * sound.c: Use EMACS_INT rather than size_t. --- src/sound.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/sound.c b/src/sound.c index 55207ddcf51..794c8e64e54 100644 --- a/src/sound.c +++ b/src/sound.c @@ -235,11 +235,11 @@ struct sound_device /* Return a preferred data size in bytes to be sent to write (below) each time. 2048 is used if this is NULL. */ - size_t (* period_size) (struct sound_device *sd); + EMACS_INT (* period_size) (struct sound_device *sd); /* Write NYBTES bytes from BUFFER to device SD. */ void (* write) (struct sound_device *sd, const char *buffer, - size_t nbytes); + EMACS_INT nbytes); /* A place for devices to store additional data. */ void *data; @@ -291,7 +291,7 @@ static void vox_configure (struct sound_device *); static void vox_close (struct sound_device *sd); static void vox_choose_format (struct sound_device *, struct sound *); static int vox_init (struct sound_device *); -static void vox_write (struct sound_device *, const char *, size_t); +static void vox_write (struct sound_device *, const char *, EMACS_INT); static void find_sound_type (struct sound *); static u_int32_t le2hl (u_int32_t); static u_int16_t le2hs (u_int16_t); @@ -600,9 +600,9 @@ wav_play (struct sound *s, struct sound_device *sd) else { char *buffer; - ssize_t nbytes = 0; - size_t blksize = sd->period_size ? sd->period_size (sd) : 2048; - size_t data_left = header->data_length; + EMACS_INT nbytes = 0; + EMACS_INT blksize = sd->period_size ? sd->period_size (sd) : 2048; + EMACS_INT data_left = header->data_length; buffer = (char *) alloca (blksize); lseek (s->fd, sizeof *header, SEEK_SET); @@ -690,9 +690,9 @@ au_play (struct sound *s, struct sound_device *sd) SBYTES (s->data) - header->data_offset); else { - size_t blksize = sd->period_size ? sd->period_size (sd) : 2048; + EMACS_INT blksize = sd->period_size ? sd->period_size (sd) : 2048; char *buffer; - ssize_t nbytes; + EMACS_INT nbytes; /* Seek */ lseek (s->fd, header->data_offset, SEEK_SET); @@ -895,7 +895,7 @@ vox_init (struct sound_device *sd) /* Write NBYTES bytes from BUFFER to device SD. */ static void -vox_write (struct sound_device *sd, const char *buffer, size_t nbytes) +vox_write (struct sound_device *sd, const char *buffer, EMACS_INT nbytes) { if (emacs_write (sd->fd, buffer, nbytes) != nbytes) sound_perror ("Error writing to sound device"); @@ -952,7 +952,7 @@ alsa_open (struct sound_device *sd) alsa_sound_perror (file, err); } -static size_t +static EMACS_INT alsa_period_size (struct sound_device *sd) { struct alsa_params *p = (struct alsa_params *) sd->data; @@ -1155,13 +1155,13 @@ alsa_choose_format (struct sound_device *sd, struct sound *s) /* Write NBYTES bytes from BUFFER to device SD. */ static void -alsa_write (struct sound_device *sd, const char *buffer, size_t nbytes) +alsa_write (struct sound_device *sd, const char *buffer, EMACS_INT nbytes) { struct alsa_params *p = (struct alsa_params *) sd->data; /* The the third parameter to snd_pcm_writei is frames, not bytes. */ int fact = snd_pcm_format_size (sd->format, 1) * sd->channels; - size_t nwritten = 0; + EMACS_INT nwritten = 0; int err; while (nwritten < nbytes)