]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
audio_format_name(): Add an assert().
authorAndre Noll <maan@systemlinux.org>
Sat, 15 Sep 2007 07:39:18 +0000 (09:39 +0200)
committerAndre Noll <maan@systemlinux.org>
Sat, 15 Sep 2007 07:39:18 +0000 (09:39 +0200)
The paraslash code should never request the name of an audio format
with invalid id. Introduce the ARRAY_SIZE macro to get the proper
upper bound for the number of supported audio formats.

para.h
vss.c

diff --git a/para.h b/para.h
index a580b14c9946bf9d10d1062a49b445e295ba72ff..5dec070f00458bd59d62fbb8fed1b3bc60cb31da 100644 (file)
--- a/para.h
+++ b/para.h
@@ -206,5 +206,8 @@ static inline int para_random(unsigned max)
        return ((max + 0.0) * (rand() / (RAND_MAX + 1.0)));
 }
 
-/* Round up x to a multiple of y */
+/** Round up x to a multiple of y */
 #define ROUND_UP(x, y) (((x) + (y - 1) / (y)) * (y))
+
+/** Get the size of an array */
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
diff --git a/vss.c b/vss.c
index 2de7a30c7bdc328cc82041135918a70da02c9578..98ad11f610087ffd5319adbbb8ecf503ccdb3b88 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -144,16 +144,17 @@ unsigned int vss_paused(void)
 }
 
 /**
- * get the name of the given audio format
+ * Get the name of the given audio format.
  *
- * \param i the audio format number
+ * \param i The audio format number.
  *
  * This returns a pointer to statically allocated memory so it
  * must not be freed by the caller.
  */
 const char *audio_format_name(int i)
 {
-       return i >= 0?  afl[i].name : "(none)";
+       assert(i >= 0 && i < ARRAY_SIZE(afl));
+       return afl[i].name;
 }
 
 /**