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.

Filter by
Sorted by
Tagged with
-2 votes
1 answer
51 views

How to fix this Excel VBA Overflow Error? [closed]

portion of code with error vba overflow error Hello. Do you know how I can edit my code to run the same equation shown here without error? It seems that I am attempting to run or am resulting in a ...
Jon Fiscus's user avatar
0 votes
0 answers
38 views

Why isn't an (intentional) overflow occuring in my python FizzBuzz implementation?

I noticed that two out of three of the values generally associated with FizzBuzz are one less than a value of 2n, and that made me want to try an implementation where it uses overflows instead of ...
NyanSequitur's user avatar
0 votes
1 answer
74 views

Does golang have int32 overflow? [duplicate]

func overFlowTest() { maxInt32 := math.MaxInt32 overflowedValue := maxInt32 + 1 fmt.Println("Max Int32:", maxInt32) fmt.Println("Overflowed Value:", ...
mercuryRising's user avatar
0 votes
1 answer
53 views

How to emit a 64 bit unsigned integer with a PyQt signal

I ran into integer overflow issues when using PyQt5.QtCore.pyqtSignal(int) in the past, because it seems that the python int becomes a C int (32 bit signed integer) in the C++ call. This limits the ...
PiRK's user avatar
  • 923
0 votes
0 answers
19 views

add the value stored in two linked lists and return a linked lists with the sum of the two numbers

my code seems to work, since it passes almost all the tests for this leetcode problem, however one of the tests is includes an extremely big value, which breaks my code. the test case in particular ...
Breach's user avatar
  • 1
0 votes
2 answers
128 views

Numpy invalid value encountered in scalar divide and overflow in exp

Here is what I am trying to calculate: def attraction(b1, b2, b3): a1=10 * b1 + 20 * b2 + 6 * b3 a2=12 * b1 + 18 * b2 + 10 * b3 a3=0 * b1 + 10 * b2 + 30 * b3 return ...
jasmine's user avatar
  • 13
3 votes
1 answer
78 views

Checking the SHL x86 assembly instruction for overflow

What is an easy way to check after the SHL EAX, CL instruction whether the theoretical result (EAX times (2 power CL)) fits into EAX? The question is about unsigned integers. I hoped for something ...
Kolodez's user avatar
  • 625
0 votes
1 answer
41 views

Detecting for Overflow using addu in MIPS

I am struggling with the implementation in MIPS of detecting for overflow and throwing an error using addu. This is for a school assignment. We were given code that was a very basic bank ledger. The ...
TJream's user avatar
  • 5
0 votes
0 answers
51 views

How do I handle integer overflow while checking for armstrong numbers?

While solving a problem on exercism , I am failing the following test case: Test Failure thread 'properly_handles_overflow' panicked at 'attempt to add with overflow', src/lib.rs:9:9 use std::io; pub ...
sidharth singh's user avatar
2 votes
2 answers
119 views

JsonCpp do not protect from uint64 overflow and have weird behavior

I am playing around with JsonCpp and have noticed weird behavior when getting to the end of uint64 range. Numbers in range works properly. Numbers above range but between [2**64,2**64+2**11] return 0. ...
Danny Cohen's user avatar
0 votes
0 answers
36 views

EIntOverflow in Delphi 7

I'm using this code. The mod line triggers an integer overflow (Delphi 7) iValue : cardinal; iWord : word; ... if iValue mod iWord > 0 then ... As it is on a customer PC with no way to debug, I ...
user382591's user avatar
  • 1,370
24 votes
3 answers
4k views

Why is optimization forbidden if a C compiler cannot prove lack of UB?

If a C program has undefined behavior, anything can happen. Therefore compilers may assume that any given program does not contain UB. So, suppose our program contains the following: x += 5; /* Do ...
Joshua's user avatar
  • 351
0 votes
3 answers
112 views

What is the correct way to determine `ticks` from clock `freq` while avoiding overflow in C on a microcontroller?

What is the correct way to multiply and divide ints in C to avoid overflow? I want to determine how many ticks of a timer running at freq (in Hz) will take to make a delay (in ms). This should be ...
SRobertJames's user avatar
  • 8,551
3 votes
4 answers
125 views

Integer Overflow when Passing Arguments in C

I think I'm having an integer overflow issue and I'm not sure how to fix it. I just started C coming from Python and JS and this is all new to me. I put a really simple example below of what is ...
Derrick Mei's user avatar
0 votes
4 answers
142 views

unsigned long long resTestBad = 0xffffffff + 1; print 0 with %llu, but unsigned long long resA = 4294967295 + 1; print 4294967296 with %llu

It seems that I found a bug when print value of (0xffffffff + 1) with %llu is 0, see below code: unsigned long long resTestBad = 0xffffffff + 1; // number of f is 8 printf("resTestBad is %llu, ...
Tom's user avatar
  • 463
4 votes
3 answers
91 views

Does a variable holding result of signed integer overflow (side effect of post incr.) and, after that, never used it in any expression, result in UB?

Consider this program #include <limits.h> int main (void) { int i = 0; // Assume, user is a fair person, following the instruction strictly.. printf ("Enter a number in the ...
H.S.'s user avatar
  • 11.8k
0 votes
1 answer
28 views

Error in integers when building Arpack-ng with mkl

I'm trying to write a program that is going to use both Arpack-ng and MKL routines. I was testing the behavior by running a simple code which use a single call to the function dsaupd, which should ...
VINCENZO BISOGNO's user avatar
0 votes
0 answers
22 views

overflow error encountered when running gradient descent

I am constantly encountering these kind of overflow errors in my python code for Gradient Descent Algorithm. e.g. RuntimeWarning: overflow encountered in scalar add RuntimeWarning: overflow ...
Sagnik's user avatar
  • 1
3 votes
1 answer
65 views

Different numpy overflow behavior on mac vs linux

I'm encountering different overflow behavior on Mac vs Linux with the same version of numpy. MWE: import numpy as np arr = np.arange(0, 2 * 4e9, 1e9, dtype=float) print(arr.astype(np.uint32)) print(np....
Jayson Vavrek's user avatar
0 votes
3 answers
95 views

Why does gcc ignore the "unsigned" data type statements? [duplicate]

One of the numbers for testing my function needs 64 bits to be stored and since I'm coding in C I need an unsigned long long to store such a number. When I try to define a variabile with that data ...
giulio's user avatar
  • 23
1 vote
3 answers
89 views

Why does this calculation result in different values depending on whether arguments come from np.arange, or an int literal is used?

Inputs: f = lambda a: 6.91581104e-08 * (a**2) + (-6.00953365e-03) * a + 1.28878592e+02 {a: f(a) for a in np.arange(46000, 47000, 100)} Outputs: {46000: -1.2213942936000137, 46100: -1....
Juin ss's user avatar
  • 11
2 votes
3 answers
148 views

What optimizations are possible when loop variable is undefined on overflow?

This article features an example snippet of C code which the compiler can optimize thanks to the fact that overflow is undefined for the type of the loop counter. Here's the snippet with the comment ...
Enlico's user avatar
  • 23.9k
0 votes
1 answer
90 views

Integer overflow vulnerabilities in ASP.NET Core applications

I have the following controller method in my application: [HttpGet] public async Task<IActionResult> GetAllBooksAsync([FromQuery] string pageNo, string itemsPerPage) { int intSkip = int....
Yashoja Lakmith's user avatar
1 vote
1 answer
112 views

How can I check over-/underflow when converting double to int in C++? [duplicate]

when learning about static_cast and dynamic_cast i saw an advice about additional checking on overflow and underflow when casting double type into int one. how can i do that here? double value1{ 4....
chrkspln's user avatar
1 vote
4 answers
127 views

Branchless way to add two UINT while avoiding overflow?

I'm curious if there's a branchless way to do this, or perhaps just a generally better way: uint16_t add_with_no_overflow(uint16_t num, uint16_t delta) { if (UINT16_MAX - delta < num) { ...
Jonathan Levin's user avatar
-1 votes
1 answer
58 views

Printing answer directly using cout gives wrong answer, whereas storing the answer and then printing using cout get accepted [closed]

I am solving problem 1A : Theatre Square(https://codeforces.com/problemset/problem/1/A) on Codeforces. Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters....
tarungaur's user avatar
1 vote
1 answer
71 views

Unreported integer-overflow in pandas math arithmetic's, pandas.eval() when using np.int16, np.int32

I need to process quite huge dataframe ~80M records, and essentially memory consumption is an issue. So columns with numerical data are shrank to possible minimum dtype, like np.int8, np.int16, np....
Fedor's user avatar
  • 31
1 vote
2 answers
73 views

What Values of Variables x and y Will Produce Incorrect Results When Testing for Overflow After Subtraction of x-y in the Following Program?

The problem I have is concerning practice problem (2.32 - pg.94) from Computer Systems: A Programmers Perspective third edition by Randal Bryant and David O'Hallaron. The problem is as follows: You ...
ChicoTabi's user avatar
-2 votes
1 answer
51 views

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

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 <iostream> int main() { double d = ...
Ajith Gupta's user avatar
5 votes
2 answers
122 views

Why does initializing a negatively-sized array cause an overflow exception?

I was unit testing in C#, and I found the following code gives an overflow exception: using System; public class Program { public static void Main() { int i = 0; ...
ADAMJR's user avatar
  • 2,090
0 votes
0 answers
7 views

How to derive correct result when overflow occurs in 2's Complement Addition?

we can always detect overflow in 2's complement addition by certain pre-defined rules, but my question is that can I somehow find out the correct result whenever overflow condition occurs in system? ...
54Y4N's user avatar
  • 15
-3 votes
1 answer
101 views

Integer Overflow Java [duplicate]

I have a question in java about integer overflow. When I search max integer and surfed integer for that binary, I got this "0111 1111 1111 1111 1111 1111 1111 1111" and also when I use the ...
Tholkappiar's user avatar
1 vote
1 answer
111 views

check for uint64_t overflow in a loop

I have a C-method which calculates the k-th number of the collatz-sequence of n. If n is / gets bigger than 64-Bit the method may return 0. My approach however has a lot of false positives. How can a ...
HeapUnderStop's user avatar
1 vote
3 answers
143 views

How do you express a large integer?

in C #include <stdio.h> #include <string.h> #include <math.h> int main() { unsigned long long result = 20170401000ULL * 20170401000; printf("%llu\n", result); ...
Kanz's user avatar
  • 11
3 votes
1 answer
213 views

How to get positive integer value of least possible negative integer?

The least possible value of the int type in C++ seems to be -2147483648. Whenever my program encounters a negative integer, I want it to be converted into a positive (by multiplying it by -1): if (n &...
KNU's user avatar
  • 2,468
-1 votes
1 answer
53 views

how to calculate the remaindor of a to the power of b divided by ten to the power of nine plus seven

I have written a code to calculate a to the power of b and then calculate pow(a,b) % 1000000007 1000000007 = pow(10,9) + 7 a and b are integers in range 1 <= a,b <= 10000000 obviously, pow(a,b) ...
Fateme's user avatar
  • 41
-1 votes
1 answer
51 views

Sum of postive intergers in a list is negative

I am trying to calculate intensities in different regions in a image(taken in 16-bit). I have created binary masks first of the different regions, then using the masking I calculate the intensities. ...
Deep's user avatar
  • 79
20 votes
2 answers
1k views

In Rust, Why does integer overflow sometimes cause compilation error or runtime error?

fn main() { let num: u8 = 255; let num2: u8 = num + 1; println!("{}, {}", num, num2); } When $ cargo build --release, this code doesn't make compile error. And $ cargo run, make ...
Junhee's user avatar
  • 203
4 votes
3 answers
157 views

Is C scanf() prohibited from checking that integers are in range?

I learned today that scanf() in C does not check if integers are representable in the specified type. For example: #include <stdio.h> int main(void) { short num; int ret = scanf("%...
John Zwinck's user avatar
-1 votes
2 answers
105 views

How can I get an integer number with 99 digits by scanf in c language?

I need to get an integer number with 99 digits. This is actually the question which I need to get an integer number with 99 digits to solve: https://quera.org/problemset/9774/ This is my code to solve ...
Pedram Arianmanesh's user avatar
-1 votes
1 answer
183 views

How to detect an overflow on assembler risc-v?

I am trying to implement a recursive factorial function in RISC-V assembly language that raises an error if there is an overflow. However, I am struggling to detect it. Is there a solution for this ? `...
rayan2338's user avatar
1 vote
1 answer
93 views

Why did Matlab choose saturation arithmetic for integers?

Matlab implements saturation arithmetic instead of wrapping on overflow for integers. While understanding the difference between the two, but not necessarily finer nuances, I wonder what was the ...
Ilya Kurnosov's user avatar
1 vote
3 answers
137 views

How to sum all long values without using BigInteger and overflow?

There are many long values, some are positive and some are negative, position and negative values exist at the same time and i have already know the sum of them will never orverflow. How can i sum ...
Jason Hapyer's user avatar
0 votes
0 answers
136 views

Unexpected "10" when converting a string to ascii code in rust

I am trying to covert a string to an ascii code in rust to turn the string into BrainFuck code: (The variable "input" is the string "hello" and this snippet starts at line 12) for ...
Cody's user avatar
  • 3
-3 votes
1 answer
78 views

Why does changing the graph in the main function result in an error?

I copied a Rust program from the website, and it ran well. However, when I changed the graph, it resulted in an error. What could be the reason for this? use std::collections::HashMap as H;type I=i64;...
licheng's user avatar
  • 127
1 vote
1 answer
92 views

OverflowError when subtracting datetime columns in pandas

I'm trying to check if the difference between two Timestamp columns in Pandas is greater than n seconds. I don't actually care about the difference. I just want to know if it's greater than n seconds, ...
Maurice's user avatar
  • 11.9k
1 vote
0 answers
26 views

Which section of the modern compiled code controls the exit of a c program?

So, In the binary files of C program compiled using old gcc versions like 3.3.6 there is a section like .dtors but there is nothing like that in the binary files of C program compiled using new gcc ...
Vignesh SB's user avatar
1 vote
2 answers
55 views

How does Java handle the intermediate values while evaluating a long arithmetic expression?

I was wondering how does Java handle the intermediate values while evaluating a mathematical expression specially when the intermediate values exceeds their storage size. For an example, int a = ...
abhimanyue's user avatar
-5 votes
2 answers
575 views

Why does GCC not detect overflow on variable initialization?

Why is it compiled without errors? What am I doing wrong? #include <stdio.h> int main (){ int n1 = 90, n2 = 93, n3 = 95; int i = 2147483647; int ii = 2147483646; int iii = ...
akaCroc's user avatar
  • 83
-3 votes
1 answer
102 views

When printing a large integer, the system automatically changed the number without giving error message. What can i do?

Here's the piece of code: int catalan(int n) { if (n<0){ return 0; } if (n<=1){ return 1; } int total = 0; for(int i=0;i<n;i++) { total += ...
Awakoto's user avatar
  • 13

1
2 3 4 5
22