phoboslab / qoa

The “Quite OK Audio Format” for fast, lossy audio compression
MIT License
767 stars 42 forks source link

Divide by 0 undefined in C99 #24

Closed thatcosmonaut closed 1 week ago

thatcosmonaut commented 1 year ago

The C99 spec states that

The result of the / operator is the quotient from the division of the first operand by the second; the result of the % operator is the remainder. In both operations, if the value of the second operand is zero, the behavior is undefined.

In qoaconv.c L270:

double psnr = 1.0/0.0;

This refuses to compile on some compilers like MSVC.

Changing 1.0/0.0 to the INFINITY macro seems to work fine.

PallHaraldsson commented 1 week ago

Fixed here to NaN https://github.com/phoboslab/qoa/pull/57/commits/66ee62d0ff59b55d3ddd1833e1ac6802d9cc1ace then later to INFINITY. The line number is different, since it must have moved, I do not see such elsewhere.