Update of /cvsroot/pclasses/pclasses2/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15534
Modified Files:
Date.cpp
Log Message:
- Added some validity checks to class Date
Index: Date.cpp
===================================================================
RCS file: /cvsroot/pclasses/pclasses2/src/Date.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- Date.cpp 23 Jan 2005 01:13:20 -0000 1.5
+++ Date.cpp 7 Jun 2005 22:43:35 -0000 1.6
@@ -26,7 +26,8 @@
Date::Date(unsigned int year, unsigned int month, unsigned int day) throw(InvalidDate)
: _year(year), _month(month), _day(day)
{
- if(month > 12 || day > daysInMonth(month, year))
+ if(month < 1 || month > 12 || day < 1
+ || day > daysInMonth(month, year))
throw InvalidDate("Invalid date", P_SOURCEINFO);
}
@@ -51,7 +52,7 @@
void Date::setMonth(unsigned int month) throw(InvalidDate)
{
- if(month > 12)
+ if(month < 1 || month > 12)
throw InvalidDate("Invalid month", P_SOURCEINFO);
_month = month;
}
@@ -122,6 +123,9 @@
unsigned int Date::daysInMonth(unsigned int month, unsigned int year)
throw(InvalidDate)
{
+ if(month < 1 || month > 12)
+ throw InvalidDate("Invalid month", P_SOURCEINFO);
+
unsigned int dim = _daysInMonth[month - 1];
if(isLeapYear(year) && month > 1)
return dim + 1;
|