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
-1
votes
1 answer

Negative input crashes program

I have the following function: char *ft_substr(char const *s, unsigned int start, size_t len) { char *substr; if (!s) return (NULL); if (start > ft_strlen(s)) len = 0; if (start <= ft_strlen(s) && s[start] !=…
-1
votes
1 answer

How to handle overflow of unsigned int in C?

How can I change line 6 to handle the integer overflow so that this code will never terminate (while still increasing i in each loop iteration)? 1 int main() { 2 unsigned int i; 3 i = 1; 4 while (i > 0) { 5 printf("%u \n", i); 6 …
robertsni
  • 1
  • 1
-1
votes
1 answer

How to check an integer in 32 bit environment in python

I am solving leetcode problem 7 reverse integer with condition Assume the environment does not allow you to store 64-bit integers (signed or unsigned). Below is my code class Solution: def reverse(self, x: int) -> int: if x val =…
sahasrara62
  • 10,069
  • 3
  • 29
  • 44
-1
votes
2 answers

Integer overflow takes place even if I type cast to long int (C++)

I am trying to understand the phenomenon of overflow and decided to demonstrate the same by executing the piece of code provided below: #include using namespace std; int main(){ int a = 100000; int b = 100000; cout << a…
-1
votes
3 answers

sum of positive integer returning negative number - C

Beginner in C language. I suspect it may be due to overflow, but could not solve this simple exercise: program to compute the sum of squares of all the natural numbers smaller than 10000 I initially tried: #include int main() { …
user305883
  • 1,635
  • 2
  • 24
  • 48
-1
votes
1 answer

Numpy overflow with np.divide(). RuntimeWarning: overflow encountered in ushort_scalars

I am running the following code on 2 images: ndvi = np.divide(img8 - img4, img8+img4) invalid = (ndvi > 1).any() if invalid: print("Stopping Execution") print(ndvi) img8 and img4 are 2 images and have all positive values. ndvi is…
Raghav Arora
  • 148
  • 1
  • 14
-1
votes
1 answer

Assignment went wrong. Is this a bug of gcc?

//filename:mt.c //filename is useful to understand the gcc command #include int isTmax(int x); int main() { printf("wtf %d\n", isTmax(0x7fffffff)); return 1; } int isTmax(int x) { int y = ((x + x + 2) ^ 1); int z = (!(~(x…
-1
votes
1 answer

If a variable counting hundredths of a second is stored in a signed long 32-bit integer

If a variable counting hundredth of a second is stored in a signed long 32-bit integer, how many days, to two decimals, will it take until that integer overflows?
-1
votes
2 answers

What's the most efficient way to perform bounded addition?

Given an unsigned integer x and a signed integer dx, what's the most efficient way to perform x = x + dx while preventing over/underflow? I could do something like: unsigned int x; int dx; ... long int result = (long int)(x + dx); if (result < 0)…
Jeff L
  • 491
  • 5
  • 14
-1
votes
8 answers

Why do i get a wrong value for `i` integer?

Below I have simple C++ code to generate numbers with a length of 18. When I call the gen_nums function, i is equal to 1569325055 as if the number that I assign to the i variable was too big for it. #include using namespace std; void…
Sec Team
  • 47
  • 8
-1
votes
2 answers

Which "C" implementation(s) do not implement modulo arithmetic for signed integers?

In reference to C11 draft, section 3.4.3 and C11 draft, section H.2.2, I'm looking for "C" implementations that implement behaviour other than modulo arithmetic for signed integers. Specifically, I am looking for instances where this is the default…
rtx13
  • 2,580
  • 1
  • 6
  • 22
-1
votes
1 answer

mysql, BIGINT value is out of range

I looked at some of the other answers for similar questions but none of them seemed to help me. [2020-01-28 23:26:29] CDbCommand failed to execute the SQL statement: SQLSTATE[22003]: Numeric value out of range: 1690 BIGINT value is out of range…
-1
votes
1 answer

Integer overflow encountered in sum

I was under the impression that python Integers are arbitrary precision. But today while solving a leetCode problem, and multiple submissions with Wrong Answer, I finally added mod to my solution and it worked. I am confused as to why it happened,…
Wajahat
  • 1,593
  • 3
  • 20
  • 47
-1
votes
1 answer

How to set a constant to negative value in Go

I am writing code in Go to call some of the Windows trust and crypt dlls to verify file signatures. There are many constants in wincrypt.h that I have tried to port over verbatim but i've hit some issues with integer overflow. For example, all of…
incubus
  • 681
  • 1
  • 5
  • 21
-1
votes
2 answers

How to Integer overflowed value when Integer is drived from Integer.parseInt("2147483647");

Lets consider below lines of code. 1- int ExA = Integer.parseInt("123"); 2- int ExB = Integer.parseInt("2147483660"); if we execute line 1 than variable ExA will be successfully populated by 123 but if we execute line 2 than we will…
Farhan
  • 105
  • 1
  • 10