IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 7, 2004, 2:08:27 PM (22 years ago)
Author:
harman
Message:

Added splint changes

File:
1 edited

Legend:

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

    r578 r614  
    1010 *  @author Ross Harman, MHPCC
    1111 *   
    12  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-05-05 20:43:22 $
     12 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-05-08 00:08:27 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    5555/*****************************************************************************/
    5656
    57 /** Private function to return a byte.
    58  *
    59  *  Finds the byte containing the bit within the byte array.
    60  *
    61  *  @return  char*: Pointer to byte in which bit is contained.
    62  */
    63 static char* getByte(int bit, const psBitSet *restrict inMask)
    64 {
    65     int index = 0;
    66     char *byte = 0;
    67     index = bit/8;
    68     byte = inMask->bits+index;
    69 
    70     return byte;
    71 }
    72 
    7357/** Private function to create a mask.
    7458 *
     
    8064static char mask(int bit)
    8165{
    82     char mask = 0x01;
     66    char mask = (char)0x01;
     67    // Ignore splint warning about negative bit shifts
     68    /*@i@*/
    8369    mask = mask << (bit%8);
    8470
     
    9177psBitSet* psBitSetAlloc(int n)
    9278{
    93     psBitSet *newObj = psAlloc(sizeof(psBitSet));
     79    psBitSet *newObj = NULL;
     80
     81    if(n <= 0) {
     82        psError(__func__, " : Line %d - Allocation size must be >= 0: size = %d\n", __LINE__, n);
     83        return 0;
     84    }
     85
     86    newObj = psAlloc(sizeof(psBitSet));
    9487    newObj->n = n;
     88
     89    // Ignore splint warning about releasing pointer members, since they've not been allocated yet
     90    /*@i@*/
    9591    newObj->bits = psAlloc(sizeof(char)*n);
    9692    memset(newObj->bits, n, 0);
     
    10197void psBitSetFree(psBitSet *restrict inBitSet)
    10298{
     99    if(inBitSet == NULL) {
     100        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument\n", __LINE__);
     101        return;
     102    }
    103103    psFree(inBitSet->bits);
    104104    psFree(inBitSet);
     
    107107psBitSet* psBitSetSet(psBitSet *inBitSet, int bit)
    108108{
    109     char* byte = getByte(bit, inBitSet);
     109    char* byte = NULL;
     110
     111    if(inBitSet == NULL) {
     112        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument\n", __LINE__);
     113        return inBitSet;
     114    } else if(bit < 0) {
     115        psError(__func__, " : Line %d - Negative bit position not allowed: %d\n", __LINE__, bit);
     116        return inBitSet;
     117    }
     118
     119    // Variable byte is the byte in the array that contains the bit to be set
     120    byte = inBitSet->bits+bit/8;
    110121    *byte |= mask(bit);
    111122
     
    115126int psBitSetTest(const psBitSet *inBitSet, int bit)
    116127{
    117     char* byte = getByte(bit, inBitSet);
    118     if((*byte&mask(bit)) == 0) {
     128    char* byte = NULL;
     129
     130    if(inBitSet == NULL) {
     131        psError(__func__, " : Line %d - Null psBitSet for inBitSet argument\n", __LINE__);
     132        return 0;
     133    } else if(bit < 0) {
     134        psError(__func__, " : Line %d - Negative bit position not allowed: %d\n", __LINE__, bit);
     135        return 0;
     136    }
     137
     138    // Variable byte is the byte in the array that contains the bit to be tested
     139    byte = inBitSet->bits+bit/8;
     140    if((int)(*byte&mask(bit)) == 0) {
    119141        return 0;
    120142    }
     
    191213    int i = 0;
    192214    int numBits = inBitSet->n*8;
    193     char* outString = psAlloc(numBits);
     215    char* outString = psAlloc((size_t)numBits);
    194216    for(i=0; i<numBits; i++) {
    195         outString[numBits-i-1] = (psBitSetTest(inBitSet, i))?'1':'0';
     217        outString[numBits-i-1] = (psBitSetTest(inBitSet, i) == 1)?'1':'0';
    196218    }
    197219
Note: See TracChangeset for help on using the changeset viewer.