unsigned char *buf;
struct pte *pe = self_pte(cxt, pno);
+ if (!pe)
+ return -EINVAL;
+
buf = calloc(1, cxt->sector_size);
if (!buf)
return -ENOMEM;
for (i = 0; i < 4; i++) {
struct pte *pe = self_pte(cxt, i);
+ assert(pe);
pe->pt_entry = mbr_get_partition(cxt->firstsector, i);
pe->ex_entry = NULL;
pe->offset = 0;
l->ext_index = ext;
pex = self_pte(cxt, ext);
+ if (!pex) {
+ DBG(LABEL, ul_debug("DOS: uninitialized pointer to %zu pex", ext));
+ return;
+ }
pex->ex_entry = pex->pt_entry;
p = pex->pt_entry;
DBG(LABEL, ul_debug("DOS: Reading extended %zu", ext));
while (IS_EXTENDED (p->sys_ind)) {
- pe = self_pte(cxt, cxt->label->nparts_max);
-
if (cxt->label->nparts_max >= MAXIMUM_PARTS) {
/* This is not a Linux restriction, but
this program uses arrays of size MAXIMUM_PARTS.
"if you save this partition table."),
cxt->label->nparts_max);
- clear_partition(pre->ex_entry);
- partition_set_changed(cxt,
- cxt->label->nparts_max - 1, 1);
+ if (pre) {
+ clear_partition(pre->ex_entry);
+ partition_set_changed(cxt,
+ cxt->label->nparts_max - 1, 1);
+ }
return;
}
+ pe = self_pte(cxt, cxt->label->nparts_max);
+ if (!pe)
+ return;
+
if (read_pte(cxt, cxt->label->nparts_max, l->ext_offset +
dos_partition_get_start(p)))
return;
/* remove last empty EBR */
pe = self_pte(cxt, cxt->label->nparts_max - 1);
- if (is_cleared_partition(pe->ex_entry) &&
+ if (pe &&
+ is_cleared_partition(pe->ex_entry) &&
is_cleared_partition(pe->pt_entry)) {
DBG(LABEL, ul_debug("DOS: EBR[offset=%ju]: empty, remove", (uintmax_t) pe->offset));
reset_pte(pe);
for (i = 4; i < cxt->label->nparts_max; i++) {
p = self_partition(cxt, i);
- if (!dos_partition_get_size(p) &&
- (cxt->label->nparts_max > 5 || q->sys_ind)) {
+ if (p && !dos_partition_get_size(p) &&
+ (cxt->label->nparts_max > 5 || (q && q->sys_ind))) {
fdisk_info(cxt, _("omitting empty partition (%zu)"), i+1);
dos_delete_partition(cxt, i);
goto remove; /* numbering changed */
for (i = 0; i < 4; i++) {
struct pte *pe = self_pte(cxt, i);
+ assert(pe);
if (is_used_partition(pe->pt_entry))
cxt->label->nparts_cur++;
struct pte *pe = self_pte(cxt, i);
struct fdisk_dos_label *l = self_label(cxt);
+ assert(pe);
if (!mbr_is_valid_magic(pe->sectorbuffer)) {
fdisk_info(cxt, _(
"Invalid flag 0x%02x%02x of EBR (for partition %zu) will "
assert(!FDISK_IS_UNDEF(start));
assert(!FDISK_IS_UNDEF(stop));
+ assert(pe);
if (doext) {
struct fdisk_dos_label *l = self_label(cxt);
fdisk_sector_t lastplusoff;
struct pte *pe = self_pte(cxt, i);
+ assert(pe);
if (start == pe->offset)
start += cxt->first_lba;
lastplusoff = last[i] + ((part_n < 4) ? 0 : cxt->first_lba);
struct pte *pe = self_pte(cxt, 0);
struct dos_partition *p;
+ assert(pe);
for (i = 0; i < cxt->label->nparts_max; pe++,i++) {
p = pe->pt_entry;
if (is_cleared_partition(p) || IS_EXTENDED (p->sys_ind)) {
for (i = 0; i < cxt->label->nparts_max; i++) {
struct pte *pe = self_pte(cxt, i);
+ assert(pe);
if (start < pe->offset && limit >= pe->offset)
limit = pe->offset - 1;
if (start < first[i] && limit >= first[i])
sys = pa && pa->type ? pa->type->code : MBR_LINUX_DATA_PARTITION;
- if (is_used_partition(p)) {
+ if (p && is_used_partition(p)) {
fdisk_warnx(cxt, _("Partition %zu is already defined. "
"Delete it before re-adding it."),
n + 1);
if (n == 4) {
/* The first EBR is stored at begin of the extended partition */
struct pte *pe = self_pte(cxt, n);
- pe->offset = l->ext_offset;
+ assert(pe);
+ pe->offset = l->ext_offset;
} else if (n > 4) {
/* The second (and another) EBR */
struct pte *pe = self_pte(cxt, n);
+ assert(pe);
pe->offset = start - cxt->first_lba;
if (pe->offset == l->ext_offset) { /* must be corrected */
pe->offset++;
set_partition(cxt, n, 0, start, stop, sys, fdisk_partition_is_bootable(pa));
if (n > 4) {
struct pte *pe = self_pte(cxt, n);
+
+ assert(pe);
set_partition(cxt, n - 1, 1, pe->offset, stop,
MBR_DOS_EXTENDED_PARTITION, 0);
}
if (IS_EXTENDED(sys)) {
struct pte *pen = self_pte(cxt, n);
+ assert(pen);
l->ext_index = n;
l->ext_offset = start;
pen->ex_entry = p;
DBG(LABEL, ul_debug("DOS: nparts max: %zu", cxt->label->nparts_max));
pe = self_pte(cxt, cxt->label->nparts_max);
+ assert(pe);
if (!pe->sectorbuffer) {
pe->sectorbuffer = calloc(1, cxt->sector_size);
struct pte *pe = self_pte(cxt, i);
p = self_partition(cxt, i);
- if (is_used_partition(p) && !IS_EXTENDED(p->sys_ind)) {
+ if (p && is_used_partition(p) && !IS_EXTENDED(p->sys_ind)) {
check_consistency(cxt, p, i);
+ assert(pe);
if (get_abs_partition_start(pe) < first[i])
fdisk_warnx(cxt, _(
"Partition %zu: bad start-of-data."),
fdisk_sector_t e_last;
struct pte *ext_pe = self_pte(cxt, l->ext_index);
+ assert(ext_pe);
e_last = get_abs_partition_end(ext_pe);
for (i = 4; i < cxt->label->nparts_max; i++) {
total++;
p = self_partition(cxt, i);
+ assert(p);
if (!p->sys_ind) {
if (i != 4 || i + 1 < cxt->label->nparts_max)
for (i = 0; i < 4; i++) {
struct dos_partition *p = self_partition(cxt, i);
+ assert(p);
if (is_used_partition(p)) {
fdisk_sector_t start = dos_partition_get_start(p);
if (last + grain <= start)
if (!mbr_changed) {
for (i = 0; i < 4; i++) {
struct pte *pe = self_pte(cxt, i);
+
+ assert(pe);
if (pe->changed)
mbr_changed = 1;
}
for (i = 4; i < cxt->label->nparts_max; i++) {
struct pte *pe = self_pte(cxt, i);
+ assert(pe);
if (!pe->changed || !pe->offset || !pe->sectorbuffer)
continue;
if ((size_t)n - 1 + 4 < cxt->label->nparts_max) {
struct pte *pe = self_pte(cxt, n - 1 + 4);
+ assert(pe);
assert(pe->private_sectorbuffer);
*name = "EBR";
for (i = 0 ; i < cxt->label->nparts_max; i++) {
struct pte *pe = self_pte(cxt, i);
- struct dos_partition *p = pe->pt_entry;
+ struct dos_partition *p;
+
+ assert(pe);
+ p = pe->pt_entry;
if (i == 4) {
last_i = 4;
assert(fdisk_is_label(cxt, DOS));
lb = self_label(cxt);
+
pe = self_pte(cxt, n);
+ assert(pe);
+
p = pe->pt_entry;
pa->used = !is_cleared_partition(p);
if (!pa->used)
l = self_label(cxt);
p = self_partition(cxt, n);
+
pe = self_pte(cxt, n);
+ if (!pe)
+ return -EINVAL;
+
orgtype = p->sys_ind;
if (pa->type) {
for (i = 4; i < cxt->label->nparts_max; i++) {
struct pte *pe = self_pte(cxt, i);
+ assert(pe);
fprintf(stderr, "#%02zu EBR [%10ju], "
"data[start=%10ju (%10ju), size=%10ju], "
"link[start=%10ju (%10ju), size=%10ju]\n",
struct pte *cur = self_pte(cxt, i),
*nxt = self_pte(cxt, i + 1);
+ assert(cur);
+ assert(nxt);
+
if (get_abs_partition_start(cur) >
get_abs_partition_start(nxt)) {
struct pte *cur = self_pte(cxt, i),
*nxt = self_pte(cxt, i + 1);
+ assert(cur);
+ assert(nxt);
+
fdisk_sector_t noff = nxt->offset - l->ext_offset,
- ooff = dos_partition_get_start(cur->ex_entry);
+ ooff = dos_partition_get_start(cur->ex_entry);
if (noff == ooff)
continue;
pei = self_pte(cxt, i);
pek = self_pte(cxt, k);
+ assert(pei);
+ assert(pek);
+
pe = pei->ex_entry;
pei->ex_entry = pek->ex_entry;
pek->ex_entry = pe;
assert(fdisk_is_label(cxt, DOS));
pe = self_pte(cxt, i);
+ if (!pe)
+ return -EINVAL;
+
p = pe->pt_entry;
if (!is_used_partition(p) || IS_EXTENDED (p->sys_ind)) {
for (x = 0; x < cxt->label->nparts_max; x++) {
unsigned int end;
struct pte *prev_pe = self_pte(cxt, x);
- struct dos_partition *prev_p = prev_pe->pt_entry;
+ struct dos_partition *prev_p;
+
+ assert(prev_pe);
+ prev_p = prev_pe->pt_entry;
if (!prev_p)
continue;
end = get_abs_partition_start(prev_pe)