From 3e047f51d5ad36df46d553d1090e28f546af9382 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 12 Apr 2011 20:22:40 -0700 Subject: [PATCH] * 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) -- 2.39.2