Raise exception if smeone tries to initialise a date with NaN

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@26865 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2008-09-23 08:22:15 +00:00
parent ac3eb1fbce
commit 6f85f5292c
3 changed files with 17 additions and 0 deletions

View file

@ -2,6 +2,9 @@
* Source/NSThread.m: add a couple of checks to ensure correct
initialisation of class.
* Source/NSDate.m:
* Source/NSCalendarDate.m: Check for time interval since reference
date being NaN, and raise an exception.
2008-09-21 00:05-EDT Gregory John Casamento <greg_casamento@yahoo.com>

View file

@ -1511,6 +1511,12 @@ static inline int getDigits(const char *from, char *to, int limit, BOOL *error)
*/
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)seconds
{
if (isnan(seconds))
{
[NSException raise: NSInvalidArgumentException
format: @"[%@-%@] interval is not a number",
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
}
_seconds_since_ref = seconds;
if (_calendar_format == nil)
{

View file

@ -46,6 +46,8 @@
#include "GSPrivate.h"
#include <math.h>
/* These constants seem to be what MacOS-X uses */
#define DISTANT_FUTURE 63113990400.0
#define DISTANT_PAST -63113817600.0
@ -1354,6 +1356,12 @@ otherTime(NSDate* other)
- (id) initWithTimeIntervalSinceReferenceDate: (NSTimeInterval)secs
{
if (isnan(secs))
{
[NSException raise: NSInvalidArgumentException
format: @"[%@-%@] interval is not a number",
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
}
_seconds_since_ref = secs;
return self;
}