LoginSignup
1
2

More than 5 years have passed since last update.

secureCoding > ラップアラウンドを発生させない

Last updated at Posted at 2015-05-05

引用: C/C++ セキュアコーディング 第2版 by Robert C. Seacordら

NGcode.c
unsigned int i, sum;
if (sum + i > UINT_MAX) {
    // too big
} else {
    sum += i;
};
OKcode.c
unsigned int i, j, sum;
if (i > UINT_MAX - sum) {
    // too big
} else {
    sum += i;
}

NGcode.cの場合、(sum+i)がUINT_MAXを超える場合ラップアラウンドが発生し、too bigの条件は成立しない。
OKcode.cのように書かないといけない。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2