icculus/mojoAL

Uninitialized ALuint makes alIsBuffer() sad

vdweller84 opened this issue · 2 comments

Hi all,

As the title above says, using an uninitialized ALuint may cause issues with alIsBuffer() . This is likely due to the conversion
const ALsizei blockidx = (((ALsizei) name) - 1) / OPENAL_BUFFER_BLOCK_SIZE;

Where ALsizei is defined as int and ALuint is unsigned int.

So a value of, say, 3435973836, while is valid for an Aluint, makes the program crash (since (ALsizei)3435973836 = -858993460 and you get a negative index).

My question is, shouldn't functions like alIsBuffer() behave well no matter what the value of their argument is?

So the root of the problem is that ALsizei is this:

/** non-negative 32-bit integer size */
typedef int ALsizei;

Which is probably a documentation mistake to say "non-negative" as if it should be unsigned ...? It is meant to map to GLsizei, which is also a signed int.

Anyhow, that's why this is unexpectedly going negative in this (and other!) places.

Should be fixed in revision control now, along with several other places with similar issues.