Integer overflow occurs when the result of an operation is larger than the maximal value that can be represented by the underlying integer type.
Questions tagged [integer-overflow]
1056 questions
-1
votes
1 answer
Searching for theory on following overflow evasion trick
The following code is using some integer overflow preventation trick that I'm trying to understand:
// x,y,z are positive numbers
boolean check(long x, long y, long z) {
return x >= (z+y-1)/y;
}
Based on the problem definition, I assume that the…

Artyom Olshevskiy
- 354
- 2
- 5
-1
votes
1 answer
Code is integer overflowing for only 1 of 2 functionally implementations
I am solving https://leetcode.com/problems/maximum-product-subarray/submissions/
I have 2 solutions to this problem, and I believe they are equivalent. However, I obtain the error
Line 24: Char 52: runtime error: signed integer overflow: -944784000…

24n8
- 1,898
- 1
- 12
- 25
-1
votes
2 answers
Binary edit leading to erase of previously binary added number
I have a C firmware for a device which sends a set of 6 flags encoded in binary to a desktop application. In a given moment, the firmware creates an unsigned int variable where it tries to add six numbers varying from 0 to 30 encoded in 5 bits to…

Momergil
- 2,213
- 5
- 29
- 59
-1
votes
4 answers
Reverse Integer Catch overflow C++
Hello I am trying a simple reverse integer operation in c++. Code below:
#include
#include
#include
using namespace std;
class RevInteger {
public:
int reverse(int x)
{
int result = 0;
…

blackmamba591
- 151
- 2
- 11
-1
votes
1 answer
No SEG_FAULT when copying large string to small buffer after integer overflow
I'm trying to demonstrate an integer overflow bug and its consequences by writing a small code as follows:
int main(int argc, char** argv)
{
size_t len = 0;
sscanf (argv[1], "%lu", &len);
char* buffer = malloc(len + 5);
strcpy…

Seyed Mohammad
- 798
- 10
- 29
-1
votes
2 answers
hex to numeric code works fine with small numbers but largenumbers produce errors
The following code converts hex string to numeric values and it works fine with small hex numbers such as 1f. But, it doesn't work with large numbers such as "000000000000000117c80378b8da0e33559b5997f2ad55e2f7d18ec1975b9717"because the int32 can't…

Pretty_Girl5
- 49
- 1
- 1
- 7
-1
votes
4 answers
Integer Overflow and the difference between pow() and multiplication
When I tried this multiplication compiler gave an integer overflow error
int main(){
long long int x;
x = 55201 * 55201;
printf("%lld", x);
return 0;
}
But When i do the same operation with pow() function i do not get any error.…

gg1810
- 19
- 3
-1
votes
1 answer
Unsigned integers overflow does not "wrap around"
I read following line from Integer Overflow Wiki:
while unsigned integer overflow causes the number to be reduced modulo
a power of two, meaning that unsigned integers "wrap around" on
overflow.
I have below code where I am trying to create a…

hagrawal7777
- 14,103
- 5
- 40
- 70
-1
votes
1 answer
How to wrap int column around instead of overflow
Suppose a column of type unsigned int. Since 4294967295 is the largest unsigned integer, this query will fail with a overflow error:
update mytable set intcolumn = intcolumn + 1;
How could I achieve that instead of overflowing, 4294967295 + 1 will…

Lorenz Meyer
- 19,166
- 22
- 75
- 121
-1
votes
1 answer
long long variable doesn't show correct answer
its some miscalculation.
I am in trouble with large numbers.
this code works for some smaller inputs(N) but for inputs like 100000 it doesn't.
the correct final answer of result variable when N = 100000 must be 4999949998
but result in this code is…

mama23n
- 135
- 2
- 3
- 10
-1
votes
1 answer
Finding a large prime in C++: where does my integer overflow?
I wrote an implementation of the Sieve of Atkin in C++ to calculate large primes. It works perfectly fine for finding up to the 10^8th prime, but when trying to find the 10^9th prime number, I get an incorrect result.
It looks like I'm dealing with…

wvdz
- 16,251
- 4
- 53
- 90
-1
votes
4 answers
I want to make equation between two Edit text
I want to make equation between two edit text and put the output on Toast
I tried to use that way :
String data1 = one.getText().toString();
String data2 = two.getText().toString();
String RES = data1 + data2;
but this way outputted result as…

MKADAIM
- 33
- 1
- 6
-1
votes
1 answer
unsigned long long overflow with numbers in the range [10^5,10^10]
I've implemented Repeated square-and-multiply algorithm for exponentiation from book "A Handbook of Applied Cryptography (http:// cacr.uwaterloo.ca/hac/about/chap2. pdf - Algorithm 2.143), that calculates the number (a^k) mod n.
The range of…

Gabriel Augusto
- 37
- 1
- 5
-1
votes
2 answers
Interesting thing happening when I take a number, multiply it by 10, and then add 1
static int fn = 0;
static int sn = 0;
static boolean running = false;
public static void run()
{
while (running == true)
{
fn = numbers[0];
sn = numbers[1];
if (sign == 0)
{
…

Mikhail
- 31
- 6
-1
votes
1 answer
Integer Overflow in C
I have this piece of code that I need to modify to demonstrate integer overflow vulnerability. I have never done it before and need a head start.
#include
int myprintf(char* argv){
printf("%s\n", argv);
return 0;
}
int…

Panchi Sharma
- 13
- 2