I am trying to port some C code to another language. Most of the code is working, except working out what this section does. The C code I've been handed is not in a compilable state so I can't do a run time analysis, but will fix that as a last resort.
Buffer is pointer to file's raw contents.
Based on reading the code my expectation was this:
if pos = 4132, then this is trying to read a 16-bit unsigned value from file position (pos << 8) + (pos + 1).
However when I make this calculation for pos = 4132, I get a file position of 1061925, which is way beyond the end of the file.
unsigned short id;
struct file
{
char *buffer;
}
id = (*(file_instance->buffer + pos)<<8) + *(file_instance->buffer+pos+1);