IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 8767


Ignore:
Timestamp:
Sep 7, 2006, 11:24:47 AM (20 years ago)
Author:
jhoblitt
Message:

add missing include for strings.h
in parseBool();

use strncasecmp() instead of repeated calls to strncmp() where possible
fix a potental segfault by not blinding writing to *status
check that *inString is not NULL

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/types/psMetadataConfig.c

    r8766 r8767  
    1010*  @author Eric Van Alst, MHPCC
    1111*
    12 *  @version $Revision: 1.76 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2006-09-07 21:13:58 $
     12*  @version $Revision: 1.77 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2006-09-07 21:24:47 $
    1414*
    1515*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2121#include <limits.h>
    2222#include <inttypes.h>
     23#include <strings.h>
    2324
    2425#include "psAbort.h"
     
    258259                        psS32 *status)
    259260{
    260     if ( !strncmp(inString, "T", 2) || !strncmp(inString, "t", 2) ||
    261             !strncmp(inString, "1", 2) || !strncmp(inString, "TRUE", 5) ||
    262             !strncmp(inString, "true", 5) || !strncmp(inString, "True", 5)) {
     261    // if inString is NULL return flalse, status = 0
     262    if (!inString) {
     263        if (status) {
     264            *status = 0;
     265        }
     266        return false;
     267    }
     268
     269    if (!strncasecmp(inString, "T", 2) ||
     270            !strncmp(inString, "1", 2) ||
     271            !strncasecmp(inString, "true", 5)) {
     272        if (status) {
     273            *status = 0;
     274        }
    263275        return true;
    264276    }
    265     if ( !strncmp(inString, "F", 2) || !strncmp(inString, "f", 2) ||
    266             !strncmp(inString, "0", 2) || !strncmp(inString, "FALSE", 6) ||
    267             !strncmp(inString, "false", 6) || !strncmp(inString, "False", 6) ) {
     277    if ( !strncasecmp(inString, "F", 2) ||
     278            !strncmp(inString, "0", 2) ||
     279            !strncasecmp(inString, "false", 6)) {
     280        if (status) {
     281            *status = 0;
     282        }
    268283        return false;
    269284    }
    270285
    271     *status = 1;
     286    if (status) {
     287        *status = 1;
     288    }
    272289    return false;
    273290}
Note: See TracChangeset for help on using the changeset viewer.