Undefined behaviour shifting negative value in rate.c
Clang warn about the following issue:
../../lib/rate.c:746:15: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
log_scale=OC_Q57(-64);
^~~~~~~~~~~
../../lib/mathops.h:134:38: note: expanded from macro 'OC_Q57'
#define OC_Q57(_v) ((ogg_int64_t)(_v)<<57)
~~~~~~~~~~~~~~~~~^
It is unclear to me what the expected and wanted behavior here is. I tested the actual behavior with the following code:
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#define OC_Q57(_v) ((int64_t)(_v)<<57)
int main(int argc, char *argv[])
{
int64_t log_scale = OC_Q57(-64);
printf("0x%" PRIx64 "\n", log_scale);
return 0;
}
The output is 0x8000000000000000, which seem like a useless representation of -64 in Q57 format, but I do not really understand the encoder code and have no idea how it is supposed to behave.