| Line |  | 
|---|
| 1 | /* | 
|---|
| 2 | * (c) copyright 1988 by the Vrije Universiteit, Amsterdam, The Netherlands. | 
|---|
| 3 | * See the copyright notice in the ACK home directory, in the file "Copyright". | 
|---|
| 4 | * | 
|---|
| 5 | * | 
|---|
| 6 | * Module:      CARDINAL operations with overflow checking | 
|---|
| 7 | * Author:      Ceriel J.H. Jacobs | 
|---|
| 8 | * Version:     $Header: /cvsup/minix/src/lib/ack/libm2/ucheck.c,v 1.1 2005/10/10 15:27:46 beng Exp $ | 
|---|
| 9 | */ | 
|---|
| 10 |  | 
|---|
| 11 | #ifndef EM_WSIZE | 
|---|
| 12 | #define EM_WSIZE _EM_WSIZE | 
|---|
| 13 | #endif | 
|---|
| 14 | #ifndef EM_LSIZE | 
|---|
| 15 | #define EM_LSIZE _EM_LSIZE | 
|---|
| 16 | #endif | 
|---|
| 17 |  | 
|---|
| 18 | #include <m2_traps.h> | 
|---|
| 19 |  | 
|---|
| 20 | #define MAXCARD ((unsigned)-1) | 
|---|
| 21 | #if EM_WSIZE < EM_LSIZE | 
|---|
| 22 | #define MAXLONGCARD     ((unsigned long) -1L) | 
|---|
| 23 | #endif | 
|---|
| 24 |  | 
|---|
| 25 | adduchk(a,b) | 
|---|
| 26 | unsigned      a,b; | 
|---|
| 27 | { | 
|---|
| 28 | if (MAXCARD - a < b) TRP(M2_UOVFL); | 
|---|
| 29 | } | 
|---|
| 30 |  | 
|---|
| 31 | #if EM_WSIZE < EM_LSIZE | 
|---|
| 32 | addulchk(a,b) | 
|---|
| 33 | unsigned long a,b; | 
|---|
| 34 | { | 
|---|
| 35 | if (MAXLONGCARD - a < b) TRP(M2_UOVFL); | 
|---|
| 36 | } | 
|---|
| 37 | #endif | 
|---|
| 38 |  | 
|---|
| 39 | muluchk(a,b) | 
|---|
| 40 | unsigned      a,b; | 
|---|
| 41 | { | 
|---|
| 42 | if (a != 0 && MAXCARD/a < b) TRP(M2_UOVFL); | 
|---|
| 43 | } | 
|---|
| 44 |  | 
|---|
| 45 | #if EM_WSIZE < EM_LSIZE | 
|---|
| 46 | mululchk(a,b) | 
|---|
| 47 | unsigned long a,b; | 
|---|
| 48 | { | 
|---|
| 49 | if (a != 0 && MAXLONGCARD/a < b) TRP(M2_UOVFL); | 
|---|
| 50 | } | 
|---|
| 51 | #endif | 
|---|
| 52 |  | 
|---|
| 53 | subuchk(a,b) | 
|---|
| 54 | unsigned      a,b; | 
|---|
| 55 | { | 
|---|
| 56 | if (b < a) TRP(M2_UUVFL); | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | #if EM_WSIZE < EM_LSIZE | 
|---|
| 60 | subulchk(a,b) | 
|---|
| 61 | unsigned long a,b; | 
|---|
| 62 | { | 
|---|
| 63 | if (b < a) TRP(M2_UUVFL); | 
|---|
| 64 | } | 
|---|
| 65 | #endif | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.