Integer overflow occurs when the result of an operation is larger than the maximal value that can be represented by the underlying integer type.
0
votes
1answer
34 views
c integer overflow - wrap around
I need to find a signed int that is negtavie but as an unsinged int equal to 22 (meaning after a wrap around occurs).
the int is being inputed as string and converted with "atoi".
6
votes
3answers
80 views
Overflow of an enum type in C?
If I have an enum type, like:
enum week{ sunday=0, monday, tuesday, wednesday, thursday, friday, saturday};
and I have:
enum week day;
day = saturday;
day++;
What will be the value of day?
2
votes
4answers
95 views
Integer division overflows
The Problem
I have been thinking about integer (type int) overflows, and it occurs to me that division could overflow.
Example: On my current platform, I have
INT_MIN == -INT_MAX - 1
and thus
...
0
votes
1answer
32 views
Why this loop freezes my browser?
Why browser hangs executing this?
for(var i= 9007199254740993;i<9007199254740994;i++) {
console.log(i);
}
0
votes
0answers
28 views
What in my ALLOCATE is causing my integer overflow?
I have a set of code in which I declare the size of all my variables. However, I want to change them so some of the variables are allocatable.
This is (what I believe) to be the relevant code of the ...
1
vote
1answer
40 views
Visual Basic 2010 Overflow Error
So I'm making a game with an infinitaly expandable length of numbers and I've gone to 2.1 Billion. This gives an overflow error.
Arithmetic operation resulted in an overflow.
In my code I have ...
0
votes
1answer
47 views
Integer promotions, value bits, and multiplying [duplicate]
If we multiply two uint32_t types and they type inton this system has 63 value bits and one sign bit, then those values are converted to int( integer promotions ), multiplied, and converted back to ...
4
votes
2answers
61 views
Do C# and Java longs form a commutative ring?
A ring is a standard mathematical structure describing objects which can be added and multiplied. Do C# and Java signed longs obey all the properties of a ring? For example, is multiplication by ...
0
votes
0answers
30 views
Highest Fibonacci number that can be computed recursively using a naive C++ program
The following is a question I was asked in an interview. I'm wondering how good my answer was and what a better answer would have looked like. Note that I didn't have a calculator at hand, so all the ...
0
votes
1answer
32 views
Arithmetic operation resulted in an overflow Error
I am getting this error
Arithmetic operation resulted in an overflow
I have already looked it up on stackoverflow. still couldn't find a solution.
My code
Private m_MemReg As List(Of ...
1
vote
2answers
64 views
ASM8086: mul, imul, carry flag and overflow flag
I understood the logic of the carry flag and the overflow flag.
But, when I read this program (wrote in MASM 8086) , I got perplexed a bit.
The program intent is to tell if a quadratic equation has ...
8
votes
1answer
94 views
Do numerical programming languages distinguish between a “largest finite number” and “infinity”?
Question motivation:
In standard numerical languages of which I am aware (e.g. Matlab, Python numpy, etc.), if, for example, you take the exponential of a modestly large number, the output is ...
0
votes
0answers
44 views
Dealing with 32bit overflow assembly x86 at&t
How to deal with overflow, if I can't work on 64 bit registers? it's the only condition. Here is sample of code:
.data
m: .long 3386449920
base: .long 483778560,225763328,109240320,26664960,413385
...
0
votes
1answer
78 views
Security Vulnerability : What is the error in this piece of code?
I was reading this book on my own , just for fun , and came across the following question :
This code has a security vulnerability ; Can you find and fix it? :
bool isValidAddition(unsigned ...
1
vote
2answers
56 views
what's wrong with golang constant overflows uint64
userid := 12345
did := (userid & ^(0xFFFF << 48))
when compiling this code, I got:
./xxxx.go:511: constant -18446462598732840961 overflows int
Do you know what is the matter with this ...
2
votes
1answer
86 views
Why is this Java long overflowing? [closed]
This is very weird.
A class I wrote has the following data member:
final static long MAX_FILE_SIZE_BYTES = 50000000000L;
at one point in my code the following block is run
...
5
votes
4answers
78 views
Avoid overflow when adding numpy arrays
I want to add numpy arrays with datatyp uint8. I know that the values in these arrays may be large enough for an overflow to happen. So I get something like:
a = np.array([100, 200, 250], ...
1
vote
1answer
85 views
Sum of two long long int when they give a result bigger thant long long int?
Is there a possible way to sum two different long long int variables when the result is going to be bigger than a long long int in C?
0
votes
2answers
51 views
PHP/ MySQL Miliseconds to Hours:Minutes:Seconds
I've been tasked with making a stats "viewer" for one of our server's gamemodes. Its been going great, but the only issue I have is converting the time played to hours:minutes:seconds.
The developer ...
1
vote
1answer
31 views
MVC4 model binding and int/decimal overflow
Let's say I created a model with a property as int? type.
public class MyModel
{
[Range(-100, 100, ErrorMessage="Too large")]
public int? MyValue { get; set; }
}
In the view I use it for a ...
0
votes
4answers
74 views
C++ integer overflow
I'm just starting to teach myself C++, and have begun learning about integer overflow. Out of curiosity I wrote some tests just to see what occurs with certain integer values.
Here's my program:
...
0
votes
1answer
67 views
Get max value on arithmethic overflow
Is there a built-in way to get max value on arithmetic overflow?
Here's what I need:
var val = byte.MaxValue + 1;
//should be rounded down to byte.MaxValue
MyByteProperty = val;
P.S. I know I can ...
1
vote
3answers
94 views
Integer arithmetic: Add 1 to UINT_MAX and divide by n without overflow
Is there a way to compute the result of ((UINT_MAX+1)/x)*x-1
in C without resorting to unsigned long (where x is unsigned int)?
(respective "without resorting to unsigned long long" depending on ...
2
votes
1answer
23 views
Doctrine2 gives me wrong sequence numbers (overflow)
I'm using Symfony2 and I have some entities defined with @ORM\GeneratedValue(strategy="AUTO") and @ORM\SequenceGenerator(sequenceName="mysequence_seq"). My sequences are using very big numbers: they ...
1
vote
0answers
23 views
How to resample gini coefficient when there is an integer overflow?
I want to calculate confidence intervals for a gini coefficient and I tried to
apply the boot() function shown below for that purpose (as suggested here):
library(reldist) # just for the gini() ...
0
votes
1answer
78 views
Reliably detect integer overflow/underflow
I'm working on code that has to do the following with the result of a calculation:
If the result exceeds the limit that can be represented in PHP's integer type then throw an exception.
If the ...
2
votes
3answers
73 views
Checking if calculation will cause overflow c++
I added the elseif statement in collatz() to check if workingnumber * 3 + 1 will go over INT_MAX but when running the program some numbers which should not go over INT_MAX are reported as doing so. I ...
72
votes
5answers
4k views
Can argc overflow?
I was wandering in SO and saw this question. Then I started wondering if I can overflow argc.
Standard says that argv[argc] must be a null pointer but this will be false if argc overflow.
(I wrote a ...
1
vote
1answer
34 views
Maximum value of kernel statistics - python
Question: What is the maximum value of kernel statistic counters and how can I handle it in python code?
Context: I calculate some statistics based on kernel statistics (e.g. /proc/partitions - it'll ...
1
vote
2answers
113 views
Java 8 Unsigned Integer Addition and Potential Overflow
I'm working exercises from the book "Java SE 8 for the Really Impatient" by Cay S. Horstmann. One of the exercises based on the improvements in the Number classes asks:
Write a program that adds, ...
0
votes
3answers
49 views
Two Ways to Interpret Integer Overflow
I have read here (http://stackoverflow.com/a/27762490/4415632) that when integer overflow occurs, the most significant bits are simply cut off.
However, I have also read here ...
3
votes
4answers
97 views
C integers off, possible overflow
I'm trying to make a C program that will count and print the number of tabs, spaces, and lines input by the user. The problem is that when it prints those numbers, they are wildly off. Here is my ...
70
votes
14answers
6k views
If a 32-bit integer overflows, can we use a 40-bit structure instead of a 64-bit long one?
If, say, a 32-bit integer is overflowing, instead of upgrading int to long, can we make use of some 40-bit type if we need a range only within 240, so that we save 24 (64-40) bits for every integer?
...
1
vote
1answer
79 views
Gaps and islands SQL error
Trying to run a query to identify starts and stops for the gaps and islands in my table. I'm applying a query that I think will work for my data set but I cannot get to run properly. I am getting a ...
0
votes
2answers
52 views
Overflow while bit shifting in java
I have situation which I dont undestand.
When I do
System.out.println(1<<30);
I got very big positive number 1073741824.
But when I do
System.out.println(1<<31);
I got very low ...
2
votes
4answers
163 views
Techniques for static code analysis in detecting integer overflows
I'm trying to find some effective techniques which I can base my integer-overflow detection tool on. I know there are many ready-made detection tools out there, but I'm trying to implement a simple ...
1
vote
2answers
174 views
Equivalent of atoi for unsigned integers
I'm doing two operations involving atoi and I'm wondering how I can do this with unsigned integers because atoi seems to convert these to signed causing a wraparound integer overflow. I want to work ...
0
votes
2answers
91 views
Limit bit position of two variables before arithmetic to prevent integer overflow
I'm trying to limit arithmetic operations before they are executed to the result of at most 32 bit integers, specifically for addition.
This loop will find the bit position:
size_t ...
0
votes
2answers
63 views
Check for Integer Overflow with Boolean
This little project is based on this discussion about the best way to detect integer overflow before an operation is performed. What I want to do is have a program demonstrate the effectivity of ...
3
votes
2answers
77 views
Add with carry on Word8
I can't find a function addWithCarry :: Word8 -> Word8 -> (Word8, Bool) already defined in base. The only function documented as caring about carries seems to be addIntC# in GHC.Prim but it ...
1
vote
5answers
76 views
why left+(right-left)/2 will not overflow?
In this article: http://googleresearch.blogspot.sg/2006/06/extra-extra-read-all-about-it-nearly.html, it mentioned most quick sort algorithm had a bug (left+right)/2, and it pointed out that the ...
1
vote
0answers
65 views
PHP convert signed 64-bit integer to hex and back
On a 64-bit system, off course. I would rather not use bcmath, but I think it to be necessary:
Test code, that works, but returns the output as 64-bit unsigned integer and overflows (PHP doesn't ...
4
votes
6answers
203 views
Why didn't scala design around Integer Overflow?
I am a former Java developer and I have recently watched the insightful and entertaining introduction to Scala for Java developers by professor Venkat Subramaniam ...
2
votes
2answers
215 views
Returning integer overflow flag in Rust?
Swift has integer overflow arithmetic functions which returns a flag whether the number has been overflown or not. Do we have same thing in Rust?
0
votes
1answer
84 views
How to shorten method that checks if multiplying gives overflow
For class I have to write a method that checks if multiplying a certain rational number with an integer results in an overflow or not.
I have written following code and it works but I have a feeling ...
0
votes
0answers
25 views
Does xtea decryption have an implicit integer oveflow?
I was reading up the various implementations of XTEA and I noticed that during decryption you usually multiply the constant delta times the number or rounds, which is usually 32 or 64.
However the ...
6
votes
6answers
712 views
Why Use Integer Instead of Long?
I often see questions relating to Overflow errors with vba.
My question is why use the integer variable declaration instead of just defining all numerical variables (excluding double etc.) as long?
...
0
votes
1answer
116 views
What is the outcome of std::distance(v.begin(), v.end()) when v is bigger than INT_MAX?
Consider this code:
std::vector<char>::size_type size = static_cast<std::vector<char>::size_type>(std::numeric_limits<std::vector<char>::difference_type>::max()) + 1;
...
126
votes
9answers
24k views
Why does Java think that the product of all numbers from 10 to 99 is 0?
The following block of codes gives the output as 0.
public class HelloWorld{
public static void main(String []args){
int product = 1;
for (int i = 10; i <= 99; i++) {
...
0
votes
1answer
60 views
C Manipulating Unsigned Ints - Integer Overflow
I am experimenting with both unsigned int data types and main method parameters in simple C programs. As an experiment I wrote a program that takes an int number from the command line as a parameter ...