aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorBojidar Marinov2018-04-16 12:15:17 +0300
committerHein-Pieter van Braam2018-04-28 22:53:02 +0200
commit44f4c8e74589e9f6e626e7853b6e52b0ac5f5ba2 (patch)
treedcc126842d4d7a8b94bd6893163aa6d99257a88d /core
parent4eed7cb9b2c13e27efe88e32a3a510a46a8cf0c9 (diff)
downloadgodot-44f4c8e74589e9f6e626e7853b6e52b0ac5f5ba2.tar.gz
godot-44f4c8e74589e9f6e626e7853b6e52b0ac5f5ba2.tar.zst
godot-44f4c8e74589e9f6e626e7853b6e52b0ac5f5ba2.zip
Fix crash resulting from bad month check in core_bind.cpp
Also, make it clear that day is 0-based. This might cause very slight differcies in existing games. Fixes #18221 (cherry picked from commit 4b9cf93338984612bbb7c15c03906ba4b24d035b)
Diffstat (limited to 'core')
-rw-r--r--core/bind/core_bind.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/core/bind/core_bind.cpp b/core/bind/core_bind.cpp
index 369b07f75..e7db336dc 100644
--- a/core/bind/core_bind.cpp
+++ b/core/bind/core_bind.cpp
@@ -623,8 +623,8 @@ uint64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const {
unsigned int second = ((datetime.has(SECOND_KEY)) ? static_cast<unsigned int>(datetime[SECOND_KEY]) : 0);
unsigned int minute = ((datetime.has(MINUTE_KEY)) ? static_cast<unsigned int>(datetime[MINUTE_KEY]) : 0);
unsigned int hour = ((datetime.has(HOUR_KEY)) ? static_cast<unsigned int>(datetime[HOUR_KEY]) : 0);
- unsigned int day = ((datetime.has(DAY_KEY)) ? static_cast<unsigned int>(datetime[DAY_KEY]) : 0);
- unsigned int month = ((datetime.has(MONTH_KEY)) ? static_cast<unsigned int>(datetime[MONTH_KEY]) - 1 : 0);
+ unsigned int day = ((datetime.has(DAY_KEY)) ? static_cast<unsigned int>(datetime[DAY_KEY]) : 1);
+ unsigned int month = ((datetime.has(MONTH_KEY)) ? static_cast<unsigned int>(datetime[MONTH_KEY]) : 1);
unsigned int year = ((datetime.has(YEAR_KEY)) ? static_cast<unsigned int>(datetime[YEAR_KEY]) : 0);
/// How many days come before each month (0-12)
@@ -644,15 +644,15 @@ uint64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const {
ERR_EXPLAIN("Invalid hour value of: " + itos(hour));
ERR_FAIL_COND_V(hour > 23, 0);
- ERR_EXPLAIN("Invalid month value of: " + itos(month + 1));
- ERR_FAIL_COND_V(month + 1 > 12, 0);
+ ERR_EXPLAIN("Invalid month value of: " + itos(month));
+ ERR_FAIL_COND_V(month > 12 || month == 0, 0);
// Do this check after month is tested as valid
- ERR_EXPLAIN("Invalid day value of: " + itos(day) + " which is larger than " + itos(MONTH_DAYS_TABLE[LEAPYEAR(year)][month]));
- ERR_FAIL_COND_V(day > MONTH_DAYS_TABLE[LEAPYEAR(year)][month], 0);
+ ERR_EXPLAIN("Invalid day value of: " + itos(day) + " which is larger than " + itos(MONTH_DAYS_TABLE[LEAPYEAR(year)][month - 1]) + " or 0");
+ ERR_FAIL_COND_V(day > MONTH_DAYS_TABLE[LEAPYEAR(year)][month - 1] || day == 0, 0);
// Calculate all the seconds from months past in this year
- uint64_t SECONDS_FROM_MONTHS_PAST_THIS_YEAR = DAYS_PAST_THIS_YEAR_TABLE[LEAPYEAR(year)][month] * SECONDS_PER_DAY;
+ uint64_t SECONDS_FROM_MONTHS_PAST_THIS_YEAR = DAYS_PAST_THIS_YEAR_TABLE[LEAPYEAR(year)][month - 1] * SECONDS_PER_DAY;
uint64_t SECONDS_FROM_YEARS_PAST = 0;
for (unsigned int iyear = EPOCH_YR; iyear < year; iyear++) {