EOVERFLOW error on 32-bit Linux

By | December 26, 2017

EOVERFLOW (Value too large for defined data type) error or error with code 75 is defined in errno.h file.
The error is very common on 32-bit Linux OS when code tries to proceed with size 2 GB or more.
It is very simple to simulate the error. Let us create file with size which exceeds 2 GB. It may be done using cat command multiple times:

# cat /var/log/dpkg.log >> test.log

Now write the following c++ code:


#include <stdio.h>
#include <errno.h>
int main(int n, char ** s)
{
   printf(“overflow error test\n”);
   FILE * fl = fopen(“test.log”,”r”);
   if(fl!=NULL)
   {
      printf(“file was opened successfully\n”);
      fclose(fl);
   }
   else
   {
      printf(“file open errno: %d\n”, errno);
   }
   return 0;
}

Saving the code as overflowtest.cpp and building:

# g++ -D_FILE_OFFSET_BITS=64 -o overflowtest overflowtest.cpp

Place the file test.log in the same directory where overflowtest is located and verifying test.log size:


# ls -l
total 2184812
-rwxr-xr-x 1 root root 7432 Dec 26 17:10 overflowtest
-rw-r–r– 1 root root 268 Dec 26 17:09 overflowtest.cpp
-rw-r–r– 1 root root 2237228532 Dec 26 16:49 test.log

The size of test.log is more than 2 GB so it is good for testing.
Now start overflowtest and get EOVERFLOW error (75):


# ./overflowtest
overflow error test
file open errno: 75

If you repeat the same test on 64-bit Linux the output will be the following:


# ./overflowtest
overflow error test
file was opened successfully

To conquer the EOVERFLOW error on 32-bit Linux simple rebuild the code with -D_FILE_OFFSET_BITS=64 key:

# g++ -D_FILE_OFFSET_BITS=64 -o overflowtest overflowtest.cpp

What happens when the code is rebuilt with -D_FILE_OFFSET_BITS=64 key? This key the condition for compiler to select fopen64 function instead of fopen one.

Leave a Reply

Your email address will not be published. Required fields are marked *