Skip to content

Range check for XLALUTCToGPS()

Karl Wette requested to merge ANU-CGA/lalsuite:gps-range-checks into master

Description

This MR adds a range check to XLALUTCToGPS() to make sure the returned GPS time is within the range of an INT4. The UTC to GPS conversion is performed in INT8, then checked that this can be cast to an INT4.

It also clarifies the existing overflow error messages in XLALGPSSetREAL8() and XLALINT8NSToGPS().

Sample output in Python:

>>> import lal
>>> import datetime
>>> lal.LIGOTimeGPS(lal.LAL_INT4_MAX)
LIGOTimeGPS(2147483647, 0)
>>> lal.LIGOTimeGPS(lal.LAL_INT4_MAX + 1)
XLALGPSSetREAL8(): overflow: 2147483648 out of range of a 32-bit signed integer
XLAL Error - XLALGPSSetREAL8 (XLALTime.c:83): Input domain error
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: Input domain error
>>> lal.LIGOTimeGPS(0) + lal.LAL_INT4_MAX
LIGOTimeGPS(2147483647, 0)
>>> lal.LIGOTimeGPS(0) + lal.LAL_INT4_MAX + 1
XLALINT8NSToGPS(): overflow: 2147483648 out of range of a 32-bit signed integer
XLAL Error - XLALINT8NSToGPS (XLALTime.c:53): Input domain error
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'lal.LIGOTimeGPS' and 'int'
>>> lal.UTCToGPS(datetime.datetime(2048, 1, 24).utctimetuple())
2147472018
>>> lal.UTCToGPS(datetime.datetime(2048, 1, 25).utctimetuple())
XLALUTCToGPS(): overflow: 2147558418 (UTC 2048-01-25 00:00:00) out of range of a 32-bit signed integer
XLAL Error - XLALUTCToGPS (XLALCivilTime.c:325): Internal function call failed
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
RuntimeError: Internal function call failed

API Changes and Justification

Backwards Compatible Changes

  • This change does not modify any class/function/struct/type definitions in a public C header file or any Python class/function definitions
  • This change adds new classes/functions/structs/types to a public C header file or Python module

Backwards Incompatible Changes

  • This change modifies an existing class/function/struct/type definition in a public C header file or Python module
  • This change removes an existing class/function/struct/type from a public C header file or Python module

Review Status

Closes #186 (closed)

cc @jolien-creighton @adam-mercer @david-keitel

Merge request reports