Fix undefined behavior

http://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points