Strict aliasing
cover Strict aliasing
Patch goes with test that executes partition scanning code path (so improves our coverage a bit)
Looks like are command line --config options has some room for improvements as I had to change the global config.
Zdenek Kabelac (2):
Fix compiler warning about strict-aliasing break Testcase for partition table scanning
lib/device/device.c | 18 +++++++++--------- test/t-test-partition.sh | 30 ++++++++++++++++++++++++++++++ test/test-utils.sh | 1 + 3 files changed, 40 insertions(+), 9 deletions(-) create mode 100755 test/t-test-partition.sh
Signature · 1 line
1.7.3.1
PATCH 1/2 Fix compiler warning about strict-aliasing break
This patch not really tested - and just show a possible solution for strict-alliasing error.
So patch is just a proposal of one of many solution.
Signed-off-by Zdenek Kabelac <[email protected]>
--- lib/device/device.c | 18 +++++++++--------- 1 files changed, 9 insertions(+), 9 deletions(-)
lib/device/device.c +9 -9
@@ -58,9 +58,11 @@ static int _has_partition_table(struct device *dev) {int ret =0 ;unsigned p; -uint16_t buf[SECTOR_SIZE /sizeof (uint16_t )]; -uint16_t *part_magic; -struct partition *part; +struct { +uint8_t skip[PART_OFFSET ]; +struct partition part[4 ]; +uint16_t magic; + } __attribute__((packed)) buf;/* sizeof() == SECTOR_SIZE */ if (!dev_read (dev,UINT64_C (0 ),sizeof (buf), &buf)) return_0;
@@ -68,17 +70,15 @@ static int _has_partition_table(struct device *dev)/* FIXME Check for other types of partition table too */ /* Check for msdos partition table */ - part_magic = buf +PART_MAGIC_OFFSET /sizeof (buf[0 ]); -if ((*part_magic ==xlate16 (PART_MAGIC ))) { - part = (struct partition *) (buf +PART_OFFSET /sizeof (buf[0 ])); -for (p =0 ; p <4 ; p++, part++) { +if (buf.magic ==xlate16 (PART_MAGIC )) { +for (p =0 ; p <4 ; ++p) {/* Table is invalid if boot indicator not 0 or 0x80 */ -if ((part->boot_ind &0x7f )) { +if (buf.part[p].boot_ind &0x7f ) { ret =0 ;break ; }/* Must have at least one non-empty partition */ -if (part->nr_sects) +if (buf.part[p].nr_sects) ret =1 ; } }
Signature · 1 line
1.7.3.1
PATCH 2/2 Testcase for partition table scanning
In reply to Zdenek KabelacSigned-off-by Zdenek Kabelac <[email protected]>
--- test/t-test-partition.sh | 30 ++++++++++++++++++++++++++++++ test/test-utils.sh | 1 + 2 files changed, 31 insertions(+), 0 deletions(-) create mode 100755 test/t-test-partition.sh
test/t-test-partition.sh new file +30 -0
@@ -0,0 +1,30 @@ +#!/bin/sh +# Copyright (C) 2010 Red Hat, Inc. All rights reserved. +# +# This copyrighted material is made available to anyone wishing to use, +# modify, copy, or redistribute it subject to the terms and conditions +# of the GNU General Public License v.2. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software Foundation, +# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +# +# Testcase for bugzilla #621173 +# excercises partition table scanning code path +# + +which sfdisk || exit 200 + +LVM_TEST_CONFIG_DEVICES="types = [\"device-mapper\", 142]" + +. ./test-utils.sh + +aux prepare_pvs 1 30 + +pvs + +# create small partition table +echo "1 2" | sfdisk $dev1 + +pvs
test/test-utils.sh +1 -0
@@ -371,6 +371,7 @@ prepare_lvmconf() { cache_dir = "$TESTDIR/etc" sysfs_scan = 0 default_data_alignment = 1 + $LVM_TEST_CONFIG_DEVICES } log { syslog = 0
Signature · 1 line
1.7.3.1
cover Strict aliasing
In reply to Zdenek KabelacQuoted 3 lines · Zdenek Kabelac
Zdenek Kabelac (2):
Fix compiler warning about strict-aliasing break Testcase for partition table scanning
Reviewed-by Petr Rockai <[email protected]>
Please check in.