speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Fix a segmentation fault when used with libao 1.0.0.


From: Christopher Brannon
Subject: [PATCH] Fix a segmentation fault when used with libao 1.0.0.
Date: Fri, 30 Jul 2010 06:46:29 -0500

The libao audio library uses a structure named ao_sample_format.
Version 1.0.0 added a new element to that structure, named "matrix".
matrix should be NULL if the programmer doesn't care about it.  In
our case, it is unimportant, so NULL is the right value.
We now initialize stack-allocated variables of type ao_sample_format to
all-zeros, so that fields such as matrix are guaranteed to be zero.
Prior to this commit, matrix was uninitialized, thus causing libao to
crash.
---
 src/audio/libao.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/src/audio/libao.c b/src/audio/libao.c
index 4651a07..9010acf 100644
--- a/src/audio/libao.c
+++ b/src/audio/libao.c
@@ -73,6 +73,14 @@ int libao_play (AudioID * id, AudioTrack track);
 
 int libao_set_volume (AudioID * id, int volume);
 
+/* AO_FORMAT_INITIALIZER is an ao_sample_format structure with zero values
+   in all of its fields.  We can guarantee that the fields of a
+   stack-allocated ao_sample_format are zeroed by assigning
+   AO_FORMAT_INITIALIZER to it.
+   This is the most portable way to initialize a stack-allocated struct to
+   zero. */
+static ao_sample_format AO_FORMAT_INITIALIZER;
+
 static volatile int ao_stop_playback = 0;
 
 static int default_driver;
@@ -99,7 +107,7 @@ int libao_play (AudioID * id, AudioTrack track)
 
   int i;
 
-  ao_sample_format format;
+  ao_sample_format format = AO_FORMAT_INITIALIZER;
 
   if (id == NULL)
     return -1;
-- 
1.7.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]