Be aware of subtle overflow

Tags:

http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html

We see the following form of code very often.

int low = ...;
int high = ...;
int mid =(low + high) / 2;

But be aware of subtle overflow here. low + high can be larger than the maximum value of int range. Open ssh vunlerability was also due to subtle overflow.

Comments

  1. 한나라 ‘단상점거·몸싸움 금지법’ 추진 에라이. 이런 걸 니들이 힘있을 때 만드냐? (하고 싶은 대로 다 해 먹어라)2008-07-20 09:14:12int mid =(low + high) / 2;아항 그렇구나(C 버그)2008-07-20 09:25:22 금요일 밤에는 토요일 오후부터 비온다고 하더니, 토요일 오후에는 일요일 오후부터 비온다고 하더니. (별다른 계획 세우질 않길 잘했네)

Leave a Reply

Your email address will not be published. Required fields are marked *