icculus / mojoAL

An SDL2-based implementation of OpenAL in a single C file.
https://icculus.org/mojoAL/
zlib License
158 stars 21 forks source link

Uninitialized ALuint makes alIsBuffer() sad #28

Closed vdweller84 closed 3 months ago

vdweller84 commented 3 months ago

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?

icculus commented 3 months ago

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.

icculus commented 3 months ago

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