Stack overflow fix

The flags variable is of type int, when reading from and writing to
it via an uint64_t *, the behavior is undefined but can be really bad.