diff options
| author | dam <dam@gudinoff> | 2023-07-29 23:17:53 +0100 |
|---|---|---|
| committer | dam <dam@gudinoff> | 2023-07-29 23:17:53 +0100 |
| commit | 4fc88c787015268ecb658a72c17749b33200f9b9 (patch) | |
| tree | ffc283e7360de1bccb4788850cd52a41394f3bb8 /ttt.jai | |
| parent | 1473ed9db288f36c736726da62dd96133023a568 (diff) | |
| download | task-time-tracker-4fc88c787015268ecb658a72c17749b33200f9b9.tar.zst task-time-tracker-4fc88c787015268ecb658a72c17749b33200f9b9.zip | |
Fixed another bug on add_task.
Diffstat (limited to 'ttt.jai')
| -rw-r--r-- | ttt.jai | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -316,12 +316,13 @@ is_valid_index :: inline(db: Database, index: s64) -> bool { return index >= 0 & add_task :: (db: *Database, task: *Task = null) -> task: *Task, index: s64 { assert(db != null, ASSERT_NOT_NULL, "db"); - new_task: Task = .{}; - if task != null new_task = <<task; + // If the task belongs to this database, calling array_add might invalidate the pointer + // because the memory may be reallocated, thus we always use a copy of the task. + new_task := ifx task == null then .{} else <<task; array_add(*db.tasks, new_task); for * db.total_times { - <<it = add(<<it, task.times[it_index]); + <<it = add(<<it, new_task.times[it_index]); } idx := db.tasks.count-1; |
