[gnome-builder] git: avoid some undefined behavior
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] git: avoid some undefined behavior
- Date: Tue, 12 Jun 2018 06:20:11 +0000 (UTC)
commit 8f584eb3a0539fcde44a0507683a0d4c96bf00cc
Author: Christian Hergert <chergert redhat com>
Date: Mon Jun 11 23:19:31 2018 -0700
git: avoid some undefined behavior
src/plugins/git/ide-git-buffer-change-monitor.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/git/ide-git-buffer-change-monitor.c b/src/plugins/git/ide-git-buffer-change-monitor.c
index ba99b8712..d81596b95 100644
--- a/src/plugins/git/ide-git-buffer-change-monitor.c
+++ b/src/plugins/git/ide-git-buffer-change-monitor.c
@@ -205,7 +205,7 @@ ide_git_buffer_change_monitor_calculate_async (IdeGitBufferChangeMonitor *self,
diff = g_slice_new0 (DiffTask);
diff->file = g_object_ref (gfile);
diff->repository = g_object_ref (self->repository);
- diff->lines = g_array_new (FALSE, FALSE, sizeof (DiffLine));
+ diff->lines = g_array_sized_new (FALSE, FALSE, sizeof (DiffLine), 32);
diff->content = ide_buffer_get_content (self->buffer);
diff->blob = self->cached_blob ? g_object_ref (self->cached_blob) : NULL;
@@ -224,7 +224,7 @@ ide_git_buffer_change_monitor_get_change (IdeBufferChangeMonitor *monitor,
DiffLine key = { line + 1, 0 }; /* Git is 1-based */
DiffLine *ret;
- if (self->lines == NULL)
+ if (self->lines == NULL || self->lines->len == 0)
{
/* If within working directory, synthesize line addition. */
if (self->is_child_of_workdir)
@@ -507,6 +507,7 @@ find_or_add_line (GArray *array,
DiffLine *ret;
g_assert (array != NULL);
+ g_assert (array->data != NULL);
g_assert (line >= 0);
ret = bsearch (&key, (gconstpointer)array->data,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]