From c80b410ffe27b69a0188e4b1ac39978754135252 Mon Sep 17 00:00:00 2001 From: Guillem Jover Date: Tue, 20 Nov 2007 15:00:29 +0100 Subject: [PATCH] dereference pointer after checking it's not NULL Dereference pointer after checking it's not NULL in partutil/partutil.c. --- partutil/partutil.c | 24 ++++++++++++++++++------ 1 files changed, 18 insertions(+), 6 deletions(-) diff --git a/partutil/partutil.c b/partutil/partutil.c index 36078c0..b22f9b2 100644 --- a/partutil/partutil.c +++ b/partutil/partutil.c @@ -928,11 +928,13 @@ char * part_table_entry_get_type (PartitionTable *p, int entry) { char *s = NULL; - PartitionEntry *pe = g_slist_nth_data (p->entries, entry); + PartitionEntry *pe; if (p == NULL) goto out; + pe = g_slist_nth_data (p->entries, entry); + switch (p->scheme) { case PART_TYPE_GPT: s = get_le_guid (&(pe->data[0])); @@ -959,11 +961,13 @@ char * part_table_entry_get_uuid (PartitionTable *p, int entry) { char *s = NULL; - PartitionEntry *pe = g_slist_nth_data (p->entries, entry); + PartitionEntry *pe; if (p == NULL) goto out; + pe = g_slist_nth_data (p->entries, entry); + switch (p->scheme) { case PART_TYPE_GPT: s = get_le_guid (&(pe->data[16])); @@ -982,11 +986,13 @@ char * part_table_entry_get_label (PartitionTable *p, int entry) { char *s = NULL; - PartitionEntry *pe = g_slist_nth_data (p->entries, entry); + PartitionEntry *pe; if (p == NULL) goto out; + pe = g_slist_nth_data (p->entries, entry); + switch (p->scheme) { case PART_TYPE_GPT: s = g_utf16_to_utf8 ((const gunichar2 *) &(pe->data[56]), 36, NULL, NULL, NULL); @@ -1012,11 +1018,13 @@ part_table_entry_get_flags (PartitionTable *p, int entry) char **ss = NULL; guint32 apm_status; guint64 gpt_attributes; - PartitionEntry *pe = g_slist_nth_data (p->entries, entry); + PartitionEntry *pe; if (p == NULL) goto out; + pe = g_slist_nth_data (p->entries, entry); + ss = g_new0 (char*, 6 + 1); /* hard coded to max items we'll return */ ss[0] = NULL; n = 0; @@ -1087,12 +1095,14 @@ guint64 part_table_entry_get_offset (PartitionTable *p, int entry) { guint64 val; - PartitionEntry *pe = g_slist_nth_data (p->entries, entry); + PartitionEntry *pe; val = G_MAXUINT64; if (p == NULL) goto out; + pe = g_slist_nth_data (p->entries, entry); + switch (p->scheme) { case PART_TYPE_GPT: val = 0x200 * ((guint64) get_le64 (pe->data + 32)); @@ -1122,12 +1132,14 @@ guint64 part_table_entry_get_size (PartitionTable *p, int entry) { guint64 val; - PartitionEntry *pe = g_slist_nth_data (p->entries, entry); + PartitionEntry *pe; val = G_MAXUINT64; if (p == NULL) goto out; + pe = g_slist_nth_data (p->entries, entry); + switch (p->scheme) { case PART_TYPE_GPT: val = 0x200 * (((guint64) get_le64 (pe->data + 40)) - ((guint64) get_le64 (pe->data + 32)) + 1); -- 1.5.3.7