Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

>
>
>
Issues of 64-bit code in real programs:…

Issues of 64-bit code in real programs: qsort

Jan 11 2010
Author:

We continue the cycle of posts about 64-bit errors detected in real applications. Time passes, demands for memory being consumed grow more and more, and now the time has come when somebody decides to sort an array consisting of more than 2^31 items. For that purpose this person chooses the function qsort implemented in OpenBSD 4.5. The result is a 64-bit error detected.

Let us consider this error in detail. At the moment of writing this post, the last revision of the file "lib/libc/stdlib/qsort.c" included into OpenBSD 4.6. dates back to August, 2005. There, the function qsort employs the auxiliary variables "d" and "r" that have the type int:

void
qsort(void *aa, size_t n, size_t es,
  int (*cmp)(const void *, const void *))
{
  char *pa, *pb, *pc, *pd, *pl, *pm, *pn;
  int d, r, swaptype, swap_cnt;
  char *a = aa;
  . . . .

These variables are used to store different sizes and it leads to errors when processing a large number of items. The correction lies in declaring these variables as size_t:

size_t d, r;

This error is exemplary because it was detected only in 2010! It seems that a large number of errors in 64-bit programs will begin to occur when a standard user computer has more than 16 Gbytes of memory and programs begin to exploit it very actively.

Popular related articles


Comments (0)

Next comments next comments
close comment form