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.
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]))
}
/**
- * 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;
}
/**