IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 9, 2004, 2:29:09 PM (22 years ago)
Author:
harman
Message:

Added more error checks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/collections/psBitSet.c

    r952 r965  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-06-09 21:18:24 $
     12 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-06-10 00:29:09 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2222#include <stdio.h>
    2323#include <ctype.h>
     24#include <math.h>
    2425
    2526#include "psBitSet.h"
     
    7778psBitSet* psBitSetAlloc(int n)
    7879{
     80    int numBytes = 0;
    7981    psBitSet *newObj = NULL;
    8082
     
    8486    }
    8587
     88    numBytes = ceil(n/8.0);
    8689    newObj = psAlloc(sizeof(psBitSet));
    87     newObj->n = n;
     90    newObj->n = numBytes;
    8891
    8992    // Ignore splint warning about releasing pointer members, since they've not been allocated yet
    9093    /*@i@*/
    91     newObj->bits = psAlloc(sizeof(char)*n);
    92     memset(newObj->bits, n, 0);
     94    newObj->bits = psAlloc(sizeof(char)*numBytes);
     95    memset(newObj->bits, numBytes, 0);
    9396
    9497    return newObj;
     
    113116        return inBitSet;
    114117    } else if(bit < 0) {
    115         psError(__func__, " : Line %d - Negative bit position not allowed: %d\n", __LINE__, bit);
     118        psError(__func__, " : Line %d - Bit position too small: %d\n", __LINE__, bit);
     119        return inBitSet;
     120    } else if(bit > inBitSet->n*8-1) {
     121        psError(__func__, " : Line %d - Bit position too large: %d\n", __LINE__, bit);
    116122        return inBitSet;
    117123    }
     
    132138        return 0;
    133139    } else if(bit < 0) {
    134         psError(__func__, " : Line %d - Negative bit position not allowed: %d\n", __LINE__, bit);
     140        psError(__func__, " : Line %d - Bit position too small: %d\n", __LINE__, bit);
     141        return 0;
     142    } else if(bit > inBitSet->n*8-1) {
     143        psError(__func__, " : Line %d - Bit position too large: %d\n", __LINE__, bit);
    135144        return 0;
    136145    }
Note: See TracChangeset for help on using the changeset viewer.