Changeset 364


Ignore:
Timestamp:
Nov 15, 2012 6:51:15 AM (7 years ago)
Author:
kulshres
Message:

change alloc parameters to size_t

to avoid inadventent wrap arounds and not artificially limit the memory sizes. also adjust print format for error messages accordingly

From: Jean Utke <utke@…>

Location:
trunk/ADOL-C
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/ADOL-C/include/adolc/adalloc.h

    r354 r364  
    2424/*--------------------------------------------------------------------------*/
    2525/*                                              MEMORY MANAGEMENT UTILITIES */
    26 ADOLC_DLL_EXPORT double    *myalloc1(int);
    27 ADOLC_DLL_EXPORT double   **myalloc2(int, int);
    28 ADOLC_DLL_EXPORT double  ***myalloc3(int, int, int);
     26ADOLC_DLL_EXPORT double    *myalloc1(size_t);
     27ADOLC_DLL_EXPORT double   **myalloc2(size_t, size_t);
     28ADOLC_DLL_EXPORT double  ***myalloc3(size_t, size_t, size_t);
    2929
    3030ADOLC_DLL_EXPORT void myfree1(double   *);
  • trunk/ADOL-C/src/adalloc.c

    r106 r364  
    3636
    3737/*--------------------------------------------------------------------------*/
    38 double* myalloc1(int m) {
     38double* myalloc1(size_t m) {
    3939    double* A = (double*)ADOLC_MALLOC(m,sizeof(double));
    4040    if (A == NULL) {
    41         fprintf(DIAG_OUT,"ADOL-C error: myalloc1 cannot allocate %i bytes\n",
    42                 (int)(m*sizeof(double)));
    43         exit (-1);
    44     }
    45     return A;
    46 }
    47 
    48 /*--------------------------------------------------------------------------*/
    49 double** myalloc2(int m, int n) {
     41        fprintf(DIAG_OUT,"ADOL-C error: myalloc1 cannot allocate %zd bytes\n",
     42                (size_t)(m*sizeof(double)));
     43        exit (-1);
     44    }
     45    return A;
     46}
     47
     48/*--------------------------------------------------------------------------*/
     49double** myalloc2(size_t m, size_t n) {
    5050    double *Adum = (double*)ADOLC_MALLOC(m*n,sizeof(double));
    5151    double   **A = (double**)malloc(m*sizeof(double*));
    5252    int i;
    5353    if (Adum == NULL) {
    54         fprintf(DIAG_OUT,"ADOL-C error: myalloc2 cannot allocate %i bytes\n",
    55                 (int)(m*n*sizeof(double)));
    56         exit (-1);
    57     }
    58     if (A == NULL) {
    59         fprintf(DIAG_OUT,"ADOL-C error: myalloc2 cannot allocate %i bytes\n",
    60                 (int)(m*sizeof(double*)));
     54        fprintf(DIAG_OUT,"ADOL-C error: myalloc2 cannot allocate %zd bytes\n",
     55                (size_t)(m*n*sizeof(double)));
     56        exit (-1);
     57    }
     58    if (A == NULL) {
     59        fprintf(DIAG_OUT,"ADOL-C error: myalloc2 cannot allocate %zd bytes\n",
     60                (size_t)(m*sizeof(double*)));
    6161        exit (-1);
    6262    }
     
    6969
    7070/*--------------------------------------------------------------------------*/
    71 double*** myalloc3(int m, int n, int p) { /* This function allocates 3-tensors contiguously */
     71double*** myalloc3(size_t m, size_t n, size_t p) { /* This function allocates 3-tensors contiguously */
    7272    double *Adum = (double*) ADOLC_MALLOC(m*n*p,sizeof(double));
    7373    double **Apt = (double**)malloc(m*n*sizeof(double*));
     
    7575    int i,j;
    7676    if (Adum == NULL) {
    77         fprintf(DIAG_OUT,"ADOL-C error: myalloc3 cannot allocate %i bytes\n",
    78                 (int)(m*n*p*sizeof(double)));
     77        fprintf(DIAG_OUT,"ADOL-C error: myalloc3 cannot allocate %zd bytes\n",
     78                (size_t)(m*n*p*sizeof(double)));
    7979        exit (-1);
    8080    }
    8181    if (Apt == NULL) {
    82         fprintf(DIAG_OUT,"ADOL-C error: myalloc3 cannot allocate %i bytes\n",
    83                 (int)(m*n*sizeof(double*)));
    84         exit (-1);
    85     }
    86     if (A == NULL) {
    87         fprintf(DIAG_OUT,"ADOL-C error: myalloc3 cannot allocate %i bytes\n",
    88                 (int)(m*sizeof(double**)));
     82        fprintf(DIAG_OUT,"ADOL-C error: myalloc3 cannot allocate %zd bytes\n",
     83                (size_t)(m*n*sizeof(double*)));
     84        exit (-1);
     85    }
     86    if (A == NULL) {
     87        fprintf(DIAG_OUT,"ADOL-C error: myalloc3 cannot allocate %zd bytes\n",
     88                (size_t)(m*sizeof(double**)));
    8989        exit (-1);
    9090    }
Note: See TracChangeset for help on using the changeset viewer.