Buffer overflows and really big numbers

BlitzPlus Forums/BlitzPlus Programming/Buffer overflows and really big numbers

schilcote(Posted 2010) [#1]
A simulator game I wrote is failing because of a buffer overflow. Is there any way I can tell Blitz to use more bytes for a variable, or do all B+ integers have to be the same size?


xlsior(Posted 2010) [#2]
Integers have a fixed size -- the maximum size of an int is 2^31.
(the remaining bit is used to define positive or negative)

If you need more, you can use LONG, which is a 64 bit signed integer, and can go all the way up to 9,223,372,036,854,775,807
(At least, I'm assuming that Blitzplus supports the LONG datatype)


Sauer(Posted 2010) [#3]
I'm not entirely sure that B+ supports long, I thought it only went to float.


H&K(Posted 2010) [#4]
Hang on. Isnt buffer overflow when the program has too many temp variables?


schilcote(Posted 2010) [#5]
A buffer overflow is when you perform an operation on a variable that makes the number it contains larger than the largest number the variable can hold. In C it causes problems because you can exploit such bugs to introduce viruses and such, but in Blitz it just makes your program glitchy because your numbers are wrong.

Try writing a program that adds 1000 to a variable over and over and over again and prints the result, after a while it'll wrap around (or "overflow") to a negative number.

Perhaps I can use strings to hold long numbers instead... Can a float hold bigger numbers?


H&K(Posted 2010) [#6]
Im not sure Thats a buffer overflow, isnt it a number/variable overflow.

Isnt a buffer overflow when the stack is too small, ie too many variables


xlsior(Posted 2010) [#7]
With a buffer overflow a program is (attempting) to write outside of the allocated memory space.

An integer that's to large will 'just' roll over and contain unexpected values, but Blitz wouldn't attempt to go outside of the declared integer boundaries


Stamm(Posted 2010) [#8]
Blitz only supports 3 basic data types (I'll give the c/c++ names for them):
int, float, string

int is only the 32-bit one, b+ always reserves 4 bytes for any int/float variable. But in files/streams, 1-byte and 2-byte integers are also allowed
(although they can only be unsigned).
Afaik.

Note: I have asked for a change in this (i.e., that other variable types are implemented), but nothing happenend yet.
since this thread(post) is much newer, I ask the development team for it again.
I'd like best all basic variable types of C++, pointers and references would be nice (especially pointers) but are not a must.

Oh and the values for 'rolled' inetegers are easy to figure out, just take the last 32 digits of the number in binary, translate it into decimal (don't forget the leftmost bit is -2^31)

Last edited 2010