Avoid buffer overflow on invalid DateTime #186
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The
timestamp()
method overflows its internal buffer if any of the data fields of the providedDateTime
(save foryOff
) is larger than 99. SuchDateTime
objects are all invalid. This pull request makes the method safe for anyDateTime
, whether it is valid or not.Although it is understood that nothing meaningful should be expected out of invalid data, corrupting memory should always be avoided. The rationale is that it is fine for operations on invalid data to yield unspecified (i.e. meaningless) results, but undefined behavior (i.e. anything can happen, including a crash) should always be avoided.
Incidentally, the patched
timestamp()
method happens to return a meaningful representation, even for invalidDateTime
objects: it exposes the contents of the object members. This turned out to be useful for testing the proposedfixDateTime()
method, from pull request #185.