Unicorn with delicious cookie
Nous utilisons des cookies pour améliorer votre expérience de navigation. En savoir plus
Accepter
to the top
>
>
>
Issues of 64-bit code in real programs:…

Issues of 64-bit code in real programs: qsort

11 Jan 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

S'abonner

Comments (0)

close comment form
close form

Remplissez le formulaire ci‑dessous en 2 étapes simples :

Vos coordonnées :

Étape 1
Félicitations ! Voici votre code promo !

Type de licence souhaité :

Étape 2
Team license
Enterprise licence
** En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité
close form
Demandez des tarifs
Nouvelle licence
Renouvellement de licence
--Sélectionnez la devise--
USD
EUR
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
La licence PVS‑Studio gratuit pour les spécialistes Microsoft MVP
close form
Pour obtenir la licence de votre projet open source, s’il vous plait rempliez ce formulaire
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
I want to join the test
* En cliquant sur ce bouton, vous déclarez accepter notre politique de confidentialité

close form
check circle
Votre message a été envoyé.

Nous vous répondrons à


Si l'e-mail n'apparaît pas dans votre boîte de réception, recherchez-le dans l'un des dossiers suivants:

  • Promotion
  • Notifications
  • Spam