Questions tagged [integer-overflow]

Integer overflow occurs when the result of an operation is larger than the maximal value that can be represented by the underlying integer type.

1056 questions
-2
votes
3 answers

How to represent integers bigger as (10^6)! to use in equations to solve in java

How can we solve equations having N! constants in it , where N can be of range 1<=N<=10^6 BigInteger can only perform upto 128 bits right? Even when one do logarithm on both sides, it leaves values bigger than BigInteger.
cypronmaya
  • 520
  • 1
  • 11
  • 24
-2
votes
1 answer

Why the behavior of double to int typecasting different in x86_64 and aarch64 during the integer overflow case?

I have the following sample code which I am compiling and executing on x86_64 and aarch64 platforms but ending up with different outputs. #include int main() { double d = 2147483649; int i = d; std::cout << i << std::endl; …
-2
votes
1 answer

Is it possible to calculate the value after overflow?

I understand that if 1 is added to INT_MAX it will overflow and we will get the negative maximum. It is connected in a cycle. In the code below can I calculate the value after overflow. #include using namespace std; int main() { …
-2
votes
1 answer

Overflow after multiplying positive int8s and casting to uint32

I am trying to multiply 8-bit positive integers and cast the result to uint32. a := int8(12) b := uint32(a * a) // 4294967184 In the above code multiplying causes an overflow. But if I cast each int8 to uint32/uint8 before multiplying, I get the…
-2
votes
1 answer

Overflow in long long int

I am facing an overflow problem for this case and getting output as 7392445620511834112 , I wanted to multiply 2 large values of b and c and want to store that value. #include using namespace std; #define ll long long int int…
-2
votes
1 answer

Difference between x + x and 2*x in Java

I was reading the answers to a Leetcode problem: https://leetcode.com/problems/divide-two-integers/. This problem requires not using multiplication. After reading a few answers, I somehow had a misconception that x+x is better than 2*x in terms of…
whatsnext
  • 617
  • 7
  • 19
-2
votes
1 answer

Integer Overflow Exploit

I have this code, which have some vulnerability, but I can't seem to exploit it. For now, this is what I've noticed: 1) if argv[1] = 3 and argc = 3, then it overflows and writes argv[2] into memory of array[3] in "place_int_array" function. 2) if…
Elyasaf755
  • 2,239
  • 18
  • 24
-2
votes
1 answer

Subtracting two integers causes integer-underflow in device code

In my cuda device code I am doing a check where I subtracting the thread's id and the blockDim to see weather or not the data I might want to use is in range. But when this number goes bellow 0 it seems to wrap back around to be max…
Liiht
  • 49
  • 7
-2
votes
2 answers

Is there an integer i where i<2 && i>10?

if(i<2 && i>10){ //code here will never be reached or what? } Just in case of an integer overflow maybe?
thestruggleisreal
  • 940
  • 3
  • 10
  • 26
-2
votes
2 answers

Can the C++ sizeof() function be used to prevent integer overflows?

I'm building mathematics functions that I plan to use for cryptography. Your algorithm is useless if the code is vulnerable to exploitation. Buffers are fairly easy to protect against overflows; but what about integers? I won't share my Galois…
-2
votes
1 answer

Errors involving precedence of modulus operator and brackets with large numbers in C++

The first part of the just computes some mathematical formula, stroed in ans1, ans2 and ans3. Many sites give % and * as having the same priority in the precedence order. Should we then consider them left to right in an expression? Only difference…
-2
votes
1 answer

python integer overflow solution

I am fairly new to Python and am currently creating a "RSA Encryption" program to send Secret messages to peers. I have the program completed, but run into issues with computations. I keep getting an overflow error because the numbers I am trying to…
-2
votes
1 answer

Why does i *= 2 seem to converge to 0 for signed integers?

Consider the following code: #include int main(int argc, char* argv[]) { int i = /* something */; for (std::size_t n = 0; n < 100; ++n) { i *= 2; std::cout << i << std::endl; } } Overflowing on signed integers…
Vincent
  • 57,703
  • 61
  • 205
  • 388
-2
votes
1 answer

A result that I can't figure out

I've been learning C recently. I have difficulty understanding the result of the code below. Why is b 255 at last? unsigned char a=1; int b=0; do { b++; a++; }while(a!=0);
Manhooo
  • 115
  • 2
  • 6
-2
votes
2 answers

overflow in implicit constant conversion warning while assigning string size(string::npos) to an integer variable

How to get rid of the the warning below? size_t filesize = getFilesize(strLogFileName.c_str()); // Open file int fd = open(strLogFileName.c_str(), O_RDONLY, 0); assert(fd != -1); // Execute mmap char* mmappedData = (char *) mmap(NULL, filesize,…
user2256825
  • 594
  • 6
  • 22