aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert2011-04-12 20:22:40 -0700
committerPaul Eggert2011-04-12 20:22:40 -0700
commit3e047f51d5ad36df46d553d1090e28f546af9382 (patch)
tree534c44e9222423c084725464020143a45cb08fb5 /src
parentc183f693134f64b3950b9287cb5d51016a32e514 (diff)
downloademacs-3e047f51d5ad36df46d553d1090e28f546af9382.tar.gz
emacs-3e047f51d5ad36df46d553d1090e28f546af9382.zip
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog10
-rw-r--r--src/sound.c27
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 @@
12011-04-13 Paul Eggert <eggert@cs.ucla.edu>
2
3 * sound.c: Don't assume sizes fit in 'int'.
4 (struct sound_device.period_size, alsa_period_size):
5 Return size_t, not int.
6 (struct sound_device.write, vox_write, alsa_write):
7 Accept size_t, not int.
8 (wav_play, au_play): Use size_t to store sizes, and ssize_t to
9 record read return values.
10
12011-04-12 Andreas Schwab <schwab@linux-m68k.org> 112011-04-12 Andreas Schwab <schwab@linux-m68k.org>
2 12
3 * charset.c (Fclear_charset_maps): Use xfree instead of free. 13 * 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
235 235
236 /* Return a preferred data size in bytes to be sent to write (below) 236 /* Return a preferred data size in bytes to be sent to write (below)
237 each time. 2048 is used if this is NULL. */ 237 each time. 2048 is used if this is NULL. */
238 int (* period_size) (struct sound_device *sd); 238 size_t (* period_size) (struct sound_device *sd);
239 239
240 /* Write NYBTES bytes from BUFFER to device SD. */ 240 /* Write NYBTES bytes from BUFFER to device SD. */
241 void (* write) (struct sound_device *sd, const char *buffer, 241 void (* write) (struct sound_device *sd, const char *buffer,
242 int nbytes); 242 size_t nbytes);
243 243
244 /* A place for devices to store additional data. */ 244 /* A place for devices to store additional data. */
245 void *data; 245 void *data;
@@ -291,7 +291,7 @@ static void vox_configure (struct sound_device *);
291static void vox_close (struct sound_device *sd); 291static void vox_close (struct sound_device *sd);
292static void vox_choose_format (struct sound_device *, struct sound *); 292static void vox_choose_format (struct sound_device *, struct sound *);
293static int vox_init (struct sound_device *); 293static int vox_init (struct sound_device *);
294static void vox_write (struct sound_device *, const char *, int); 294static void vox_write (struct sound_device *, const char *, size_t);
295static void find_sound_type (struct sound *); 295static void find_sound_type (struct sound *);
296static u_int32_t le2hl (u_int32_t); 296static u_int32_t le2hl (u_int32_t);
297static u_int16_t le2hs (u_int16_t); 297static u_int16_t le2hs (u_int16_t);
@@ -600,9 +600,9 @@ wav_play (struct sound *s, struct sound_device *sd)
600 else 600 else
601 { 601 {
602 char *buffer; 602 char *buffer;
603 int nbytes = 0; 603 ssize_t nbytes = 0;
604 int blksize = sd->period_size ? sd->period_size (sd) : 2048; 604 size_t blksize = sd->period_size ? sd->period_size (sd) : 2048;
605 int data_left = header->data_length; 605 size_t data_left = header->data_length;
606 606
607 buffer = (char *) alloca (blksize); 607 buffer = (char *) alloca (blksize);
608 lseek (s->fd, sizeof *header, SEEK_SET); 608 lseek (s->fd, sizeof *header, SEEK_SET);
@@ -690,9 +690,9 @@ au_play (struct sound *s, struct sound_device *sd)
690 SBYTES (s->data) - header->data_offset); 690 SBYTES (s->data) - header->data_offset);
691 else 691 else
692 { 692 {
693 int blksize = sd->period_size ? sd->period_size (sd) : 2048; 693 size_t blksize = sd->period_size ? sd->period_size (sd) : 2048;
694 char *buffer; 694 char *buffer;
695 int nbytes; 695 ssize_t nbytes;
696 696
697 /* Seek */ 697 /* Seek */
698 lseek (s->fd, header->data_offset, SEEK_SET); 698 lseek (s->fd, header->data_offset, SEEK_SET);
@@ -895,10 +895,9 @@ vox_init (struct sound_device *sd)
895/* Write NBYTES bytes from BUFFER to device SD. */ 895/* Write NBYTES bytes from BUFFER to device SD. */
896 896
897static void 897static void
898vox_write (struct sound_device *sd, const char *buffer, int nbytes) 898vox_write (struct sound_device *sd, const char *buffer, size_t nbytes)
899{ 899{
900 ssize_t nwritten = emacs_write (sd->fd, buffer, nbytes); 900 if (emacs_write (sd->fd, buffer, nbytes) != nbytes)
901 if (nwritten < 0)
902 sound_perror ("Error writing to sound device"); 901 sound_perror ("Error writing to sound device");
903} 902}
904 903
@@ -953,7 +952,7 @@ alsa_open (struct sound_device *sd)
953 alsa_sound_perror (file, err); 952 alsa_sound_perror (file, err);
954} 953}
955 954
956static int 955static size_t
957alsa_period_size (struct sound_device *sd) 956alsa_period_size (struct sound_device *sd)
958{ 957{
959 struct alsa_params *p = (struct alsa_params *) sd->data; 958 struct alsa_params *p = (struct alsa_params *) sd->data;
@@ -1156,13 +1155,13 @@ alsa_choose_format (struct sound_device *sd, struct sound *s)
1156/* Write NBYTES bytes from BUFFER to device SD. */ 1155/* Write NBYTES bytes from BUFFER to device SD. */
1157 1156
1158static void 1157static void
1159alsa_write (struct sound_device *sd, const char *buffer, int nbytes) 1158alsa_write (struct sound_device *sd, const char *buffer, size_t nbytes)
1160{ 1159{
1161 struct alsa_params *p = (struct alsa_params *) sd->data; 1160 struct alsa_params *p = (struct alsa_params *) sd->data;
1162 1161
1163 /* The the third parameter to snd_pcm_writei is frames, not bytes. */ 1162 /* The the third parameter to snd_pcm_writei is frames, not bytes. */
1164 int fact = snd_pcm_format_size (sd->format, 1) * sd->channels; 1163 int fact = snd_pcm_format_size (sd->format, 1) * sd->channels;
1165 int nwritten = 0; 1164 size_t nwritten = 0;
1166 int err; 1165 int err;
1167 1166
1168 while (nwritten < nbytes) 1167 while (nwritten < nbytes)