Ignore:
Timestamp:
Nov 28, 2008, 7:19:09 AM (16 years ago)
Author:
Simon Hausmann
Message:

2008-11-28 Simon Hausmann <Simon Hausmann>

Reviewed by Tor Arne Vestbø.

Fix compilation on Windows CE

Port away from the use of errno after calling strtol(), instead
detect conversion errors by checking the result and the stop
position.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/DateMath.cpp

    r38830 r38831  
    716716}
    717717
     718static bool parseLong(const char* string, char** stopPosition, int base, long* result)
     719{
     720    *result = strtol(string, stopPosition, base);
     721    // Avoid the use of errno as it is not available on Windows CE
     722    if (string == *stopPosition || *result == LONG_MIN || *result == LONG_MAX)
     723        return false;
     724    return true;
     725}
     726
    718727double parseDate(const UString &date)
    719728{
     
    761770
    762771    // ' 09-Nov-99 23:12:40 GMT'
    763     char *newPosStr;
    764     errno = 0;
    765     long day = strtol(dateString, &newPosStr, 10);
    766     if (errno)
     772    char* newPosStr;
     773    long day;
     774    if (!parseLong(dateString, &newPosStr, 10, &day))
    767775        return NaN;
    768776    dateString = newPosStr;
     
    783791            return NaN;
    784792        year = day;
    785         month = strtol(dateString, &newPosStr, 10) - 1;
    786         if (errno)
     793        if (!parseLong(dateString, &newPosStr, 10, &month))
    787794            return NaN;
     795        month -= 1;
    788796        dateString = newPosStr;
    789797        if (*dateString++ != '/' || !*dateString)
    790798            return NaN;
    791         day = strtol(dateString, &newPosStr, 10);
    792         if (errno)
     799        if (!parseLong(dateString, &newPosStr, 10, &day))
    793800            return NaN;
    794801        dateString = newPosStr;
     
    797804        // This looks like a MM/DD/YYYY date, not an RFC date.
    798805        month = day - 1; // 0-based
    799         day = strtol(dateString, &newPosStr, 10);
    800         if (errno)
     806        if (!parseLong(dateString, &newPosStr, 10, &day))
    801807            return NaN;
    802808        if (day < 1 || day > 31)
     
    839845    // '99 23:12:40 GMT'
    840846    if (year <= 0 && *dateString) {
    841         year = strtol(dateString, &newPosStr, 10);
    842         if (errno)
     847        if (!parseLong(dateString, &newPosStr, 10, &year))
    843848            return NaN;
    844849    }
     
    863868        }
    864869
    865         hour = strtol(dateString, &newPosStr, 10);
     870        parseLong(dateString, &newPosStr, 10, &hour);
    866871        // Do not check for errno here since we want to continue
    867872        // even if errno was set becasue we are still looking
     
    882887                return NaN;
    883888
    884             minute = strtol(dateString, &newPosStr, 10);
    885             if (errno)
     889            if (!parseLong(dateString, &newPosStr, 10, &minute))
    886890                return NaN;
    887891            dateString = newPosStr;
     
    898902                dateString++;
    899903
    900                 second = strtol(dateString, &newPosStr, 10);
    901                 if (errno)
     904                if (!parseLong(dateString, &newPosStr, 10, &second))
    902905                    return NaN;
    903906                dateString = newPosStr;
     
    939942
    940943        if (*dateString == '+' || *dateString == '-') {
    941             long o = strtol(dateString, &newPosStr, 10);
    942             if (errno)
     944            long o;
     945            if (!parseLong(dateString, &newPosStr, 10, &o))
    943946                return NaN;
    944947            dateString = newPosStr;
     
    952955                offset = ((o / 100) * 60 + (o % 100)) * sgn;
    953956            } else { // GMT+05:00
    954                 long o2 = strtol(dateString, &newPosStr, 10);
    955                 if (errno)
     957                long o2;
     958                if (!parseLong(dateString, &newPosStr, 10, &o2))
    956959                    return NaN;
    957960                dateString = newPosStr;
     
    974977
    975978    if (*dateString && year == -1) {
    976         year = strtol(dateString, &newPosStr, 10);
    977         if (errno)
     979        if (!parseLong(dateString, &newPosStr, 10, &year))
    978980            return NaN;
    979981        dateString = newPosStr;
Note: See TracChangeset for help on using the changeset viewer.