Files
codeql/cpp/ql/src/Likely Bugs/Arithmetic/IntMultToLong.cpp
2018-08-02 17:53:23 +01:00

7 lines
312 B
C++

int i = 2000000000;
long j = i * i; //Wrong: due to overflow on the multiplication between ints,
//will result to j being -1651507200, not 4000000000000000000
long k = (long) i * i; //Correct: the multiplication is done on longs instead of ints,
//and will not overflow