Changeset 38831 in webkit for trunk/JavaScriptCore/runtime/DateMath.cpp
- Timestamp:
- Nov 28, 2008, 7:19:09 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/runtime/DateMath.cpp
r38830 r38831 716 716 } 717 717 718 static 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 718 727 double parseDate(const UString &date) 719 728 { … … 761 770 762 771 // ' 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)) 767 775 return NaN; 768 776 dateString = newPosStr; … … 783 791 return NaN; 784 792 year = day; 785 month = strtol(dateString, &newPosStr, 10) - 1; 786 if (errno) 793 if (!parseLong(dateString, &newPosStr, 10, &month)) 787 794 return NaN; 795 month -= 1; 788 796 dateString = newPosStr; 789 797 if (*dateString++ != '/' || !*dateString) 790 798 return NaN; 791 day = strtol(dateString, &newPosStr, 10); 792 if (errno) 799 if (!parseLong(dateString, &newPosStr, 10, &day)) 793 800 return NaN; 794 801 dateString = newPosStr; … … 797 804 // This looks like a MM/DD/YYYY date, not an RFC date. 798 805 month = day - 1; // 0-based 799 day = strtol(dateString, &newPosStr, 10); 800 if (errno) 806 if (!parseLong(dateString, &newPosStr, 10, &day)) 801 807 return NaN; 802 808 if (day < 1 || day > 31) … … 839 845 // '99 23:12:40 GMT' 840 846 if (year <= 0 && *dateString) { 841 year = strtol(dateString, &newPosStr, 10); 842 if (errno) 847 if (!parseLong(dateString, &newPosStr, 10, &year)) 843 848 return NaN; 844 849 } … … 863 868 } 864 869 865 hour = strtol(dateString, &newPosStr, 10);870 parseLong(dateString, &newPosStr, 10, &hour); 866 871 // Do not check for errno here since we want to continue 867 872 // even if errno was set becasue we are still looking … … 882 887 return NaN; 883 888 884 minute = strtol(dateString, &newPosStr, 10); 885 if (errno) 889 if (!parseLong(dateString, &newPosStr, 10, &minute)) 886 890 return NaN; 887 891 dateString = newPosStr; … … 898 902 dateString++; 899 903 900 second = strtol(dateString, &newPosStr, 10); 901 if (errno) 904 if (!parseLong(dateString, &newPosStr, 10, &second)) 902 905 return NaN; 903 906 dateString = newPosStr; … … 939 942 940 943 if (*dateString == '+' || *dateString == '-') { 941 long o = strtol(dateString, &newPosStr, 10);942 if ( errno)944 long o; 945 if (!parseLong(dateString, &newPosStr, 10, &o)) 943 946 return NaN; 944 947 dateString = newPosStr; … … 952 955 offset = ((o / 100) * 60 + (o % 100)) * sgn; 953 956 } else { // GMT+05:00 954 long o2 = strtol(dateString, &newPosStr, 10);955 if ( errno)957 long o2; 958 if (!parseLong(dateString, &newPosStr, 10, &o2)) 956 959 return NaN; 957 960 dateString = newPosStr; … … 974 977 975 978 if (*dateString && year == -1) { 976 year = strtol(dateString, &newPosStr, 10); 977 if (errno) 979 if (!parseLong(dateString, &newPosStr, 10, &year)) 978 980 return NaN; 979 981 dateString = newPosStr;
Note:
See TracChangeset
for help on using the changeset viewer.