[PATCH 4/7] maint: remove more dead stores and fix a bug in do_mkpartfs
Jim Meyering
meyering at redhat.com
Tue Sep 29 19:49:55 UTC 2009
* libparted/fs/ext2/ext2_mkfs.c (ext2_mkfs_create_lost_and_found_inode):
Punt: suppress clang's (aka scan-build's) warning.
* parted/parted.c (snap_to_boundaries): Remove a dead store.
(do_mkpartfs): The apparent dead store to part_name exposed a real bug.
In fact, it highlighted that while do_mkpart uses its "part_name"
variable (and calls ped_partition_set_name), do_mkpartfs did not.
(snap_to_boundaries): Remove dead store.
* libparted/unit.c (parse_chs): Likewise, and a leak.
* libparted/fs/hfs/reloc_plus.c (hfsplus_cache_from_catalog): Likewise.
(hfsplus_cache_from_extent): Remove a dead store.
(hfsplus_cache_from_attributes): Likewise.
* libparted/fs/hfs/advfs_plus.c (hfsplus_btree_search): Likewise.
* libparted/fs/ext2/ext2_block_relocator.c (ext2_block_relocate_shrink):
Remove dead store and corresponding decl.
* parted/ui.h: Mark 2nd parameter as non-null.
---
libparted/fs/ext2/ext2_block_relocator.c | 7 -------
libparted/fs/ext2/ext2_mkfs.c | 1 +
libparted/fs/hfs/advfs_plus.c | 3 +--
libparted/fs/hfs/reloc_plus.c | 9 +++------
libparted/unit.c | 3 +--
parted/parted.c | 3 ++-
parted/ui.h | 3 ++-
7 files changed, 10 insertions(+), 19 deletions(-)
diff --git a/libparted/fs/ext2/ext2_block_relocator.c b/libparted/fs/ext2/ext2_block_relocator.c
index 2f5194d..8b1b233 100644
--- a/libparted/fs/ext2/ext2_block_relocator.c
+++ b/libparted/fs/ext2/ext2_block_relocator.c
@@ -826,15 +826,8 @@ static int ext2_block_relocate_grow(struct ext2_fs *fs, struct ext2_block_reloca
static int ext2_block_relocate_shrink(struct ext2_fs *fs, struct ext2_block_relocator_state *state, blk_t newsize)
{
- int diff;
int i;
- diff = ped_div_round_up (newsize - EXT2_SUPER_FIRST_DATA_BLOCK(fs->sb),
- EXT2_SUPER_BLOCKS_PER_GROUP(fs->sb));
- diff = ped_div_round_up (diff * sizeof(struct ext2_group_desc),
- fs->blocksize);
- diff = fs->gdblocks - diff;
-
state->newallocoffset = fs->itoffset + fs->inodeblocks;
for (i=0;i<fs->numgroups;i++)
diff --git a/libparted/fs/ext2/ext2_mkfs.c b/libparted/fs/ext2/ext2_mkfs.c
index 8f6b010..eada62c 100644
--- a/libparted/fs/ext2/ext2_mkfs.c
+++ b/libparted/fs/ext2/ext2_mkfs.c
@@ -313,6 +313,7 @@ static int ext2_mkfs_create_lost_and_found_inode(struct ext2_fs *fs)
11, ".", EXT2_FT_DIR);
offset = _set_dirent(bh->data, offset, fs->blocksize, 1,
EXT2_ROOT_INO, "..", EXT2_FT_DIR);
+ (void) offset;
bh->dirty = 1;
ext2_brelse(bh, 1);
diff --git a/libparted/fs/hfs/advfs_plus.c b/libparted/fs/hfs/advfs_plus.c
index 8543904..4bcd282 100644
--- a/libparted/fs/hfs/advfs_plus.c
+++ b/libparted/fs/hfs/advfs_plus.c
@@ -76,7 +76,6 @@ hfsplus_btree_search (HfsPPrivateFile* b_tree_file, HfsPPrivateGenericKey* key,
uint8_t node_1[PED_SECTOR_SIZE_DEFAULT];
uint8_t* node;
HfsPHeaderRecord* header;
- HfsPNodeDescriptor* desc = (HfsPNodeDescriptor*) node_1;
HfsPPrivateGenericKey* record_key = NULL;
unsigned int node_number, record_number, size, bsize;
int i;
@@ -96,7 +95,7 @@ hfsplus_btree_search (HfsPPrivateFile* b_tree_file, HfsPPrivateGenericKey* key,
node = (uint8_t*) ped_malloc (bsize);
if (!node)
return 0;
- desc = (HfsPNodeDescriptor*) node;
+ HfsPNodeDescriptor *desc = (HfsPNodeDescriptor*) node;
/* Read the root node */
if (!hfsplus_file_read (b_tree_file, node,
diff --git a/libparted/fs/hfs/reloc_plus.c b/libparted/fs/hfs/reloc_plus.c
index 69ace77..be46452 100644
--- a/libparted/fs/hfs/reloc_plus.c
+++ b/libparted/fs/hfs/reloc_plus.c
@@ -478,7 +478,6 @@ hfsplus_cache_from_catalog(HfsCPrivateCache* cache, PedFileSystem* fs,
uint8_t node_1[PED_SECTOR_SIZE_DEFAULT];
uint8_t* node;
HfsPHeaderRecord* header;
- HfsPNodeDescriptor* desc = (HfsPNodeDescriptor*) node_1;
HfsPCatalogKey* catalog_key;
HfsPCatalog* catalog_data;
HfsPExtDescriptor* extent;
@@ -507,7 +506,7 @@ hfsplus_cache_from_catalog(HfsCPrivateCache* cache, PedFileSystem* fs,
node = (uint8_t*) ped_malloc(bsize);
if (!node) return 0;
- desc = (HfsPNodeDescriptor*) node;
+ HfsPNodeDescriptor *desc = (HfsPNodeDescriptor*) node;
for (; leaf_node; leaf_node = PED_BE32_TO_CPU (desc->next)) {
if (!hfsplus_file_read (priv_data->catalog_file, node,
@@ -605,7 +604,6 @@ hfsplus_cache_from_extent(HfsCPrivateCache* cache, PedFileSystem* fs,
uint8_t node_1[PED_SECTOR_SIZE_DEFAULT];
uint8_t* node;
HfsPHeaderRecord* header;
- HfsPNodeDescriptor* desc = (HfsPNodeDescriptor*) node_1;
HfsPExtentKey* extent_key;
HfsPExtDescriptor* extent;
unsigned int leaf_node, record_number;
@@ -630,7 +628,7 @@ hfsplus_cache_from_extent(HfsCPrivateCache* cache, PedFileSystem* fs,
node = (uint8_t*) ped_malloc (bsize);
if (!node) return -1;
- desc = (HfsPNodeDescriptor*) node;
+ HfsPNodeDescriptor *desc = (HfsPNodeDescriptor*) node;
for (; leaf_node; leaf_node = PED_BE32_TO_CPU (desc->next)) {
if (!hfsplus_file_read (priv_data->extents_file, node,
@@ -720,7 +718,6 @@ hfsplus_cache_from_attributes(HfsCPrivateCache* cache, PedFileSystem* fs,
uint8_t node_1[PED_SECTOR_SIZE_DEFAULT];
uint8_t* node;
HfsPHeaderRecord* header;
- HfsPNodeDescriptor* desc = (HfsPNodeDescriptor*) node_1;
HfsPPrivateGenericKey* generic_key;
HfsPForkDataAttr* fork_ext_data;
HfsPExtDescriptor* extent;
@@ -742,7 +739,7 @@ hfsplus_cache_from_attributes(HfsCPrivateCache* cache, PedFileSystem* fs,
node = (uint8_t*) ped_malloc(bsize);
if (!node) return 0;
- desc = (HfsPNodeDescriptor*) node;
+ HfsPNodeDescriptor *desc = (HfsPNodeDescriptor*) node;
for (; leaf_node; leaf_node = PED_BE32_TO_CPU (desc->next)) {
if (!hfsplus_file_read (priv_data->attributes_file, node,
diff --git a/libparted/unit.c b/libparted/unit.c
index 2cc1169..b9a252a 100644
--- a/libparted/unit.c
+++ b/libparted/unit.c
@@ -369,10 +369,9 @@ parse_chs (const char* str, const PedDevice* dev, PedSector* sector,
PedGeometry** range)
{
PedSector cyl_size = dev->bios_geom.heads * dev->bios_geom.sectors;
- char* copy = ped_strdup (str);
PedCHSGeometry chs;
- copy = ped_strdup (str);
+ char* copy = ped_strdup (str);
if (!copy)
return 0;
strip_string (copy);
diff --git a/parted/parted.c b/parted/parted.c
index 97932c8..55627bf 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -346,7 +346,6 @@ snap_to_boundaries (PedGeometry* new_geom, PedGeometry* old_geom,
EMoves start_allow, end_allow, start_want, end_want;
int adjacent;
- start_want = end_want = MOVE_NO;
start_allow = end_allow = MOVE_STILL | MOVE_UP | MOVE_DOWN;
start_part = ped_disk_get_partition_by_sector (disk, start);
@@ -987,6 +986,8 @@ do_mkpartfs (PedDevice** dev)
goto error_destroy_disk;
ped_file_system_close (fs);
+ if (part_name)
+ PED_ASSERT (ped_partition_set_name (part, part_name), return 0);
if (!ped_partition_set_system (part, fs_type))
goto error_destroy_disk;
diff --git a/parted/ui.h b/parted/ui.h
index 6fb039a..e5358e5 100644
--- a/parted/ui.h
+++ b/parted/ui.h
@@ -49,7 +49,8 @@ extern int command_line_get_sector (const char* prompt, PedDevice* dev,
PedSector* value, PedGeometry** range);
extern int command_line_get_state (const char* prompt, int* value);
extern int command_line_get_device (const char* prompt, PedDevice** value);
-extern int command_line_get_disk (const char* prompt, PedDisk** value);
+extern int command_line_get_disk (const char* prompt, PedDisk** value)
+ __attribute__((__nonnull__(2)));
extern int command_line_get_partition (const char* prompt, PedDisk* disk,
PedPartition** value);
extern int command_line_get_fs_type (const char* prompt,
--
1.6.5.rc2.177.ga9dd6
More information about the parted-devel
mailing list