FYI, I've just pushed the following changes. I ran the clang static analyzer (http://clang-analyzer.llvm.org/) on parted recently, and finally got around to addressing the problems it reported. Meanwhile, I've also just build on an F12-alpha-based system, which exposed new shadowing (link) warnings.
The most significant change here is this one: Subject: [PATCH 2/7] make PED_ASSERT handling sane: abort on false condition See the description/justification in the commit log below. >From 5748ee73326ada39f68c9d684e2964aaeac20253 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Thu, 1 Oct 2009 12:03:07 +0200 Subject: [PATCH 1/7] build: avoid a shadowing warning * libparted/fs/hfs/advfs_plus.c (hfsplus_get_empty_end): Rename local, "link" to avoid shadowing the syscall. * libparted/fs/hfs/advfs.c (hfs_get_empty_end): Likewise. --- libparted/fs/hfs/advfs.c | 12 ++++++------ libparted/fs/hfs/advfs_plus.c | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libparted/fs/hfs/advfs.c b/libparted/fs/hfs/advfs.c index b214fdc..bf4595f 100644 --- a/libparted/fs/hfs/advfs.c +++ b/libparted/fs/hfs/advfs.c @@ -268,19 +268,19 @@ hfs_get_empty_end (const PedFileSystem *fs) HfsPrivateFSData* priv_data = (HfsPrivateFSData*) fs->type_specific; HfsMasterDirectoryBlock* mdb = priv_data->mdb; - HfsPrivateLinkExtent* link; unsigned int block, last_bad, end_free_blocks; /* find the next block to the last bad block of the volume */ if (!hfs_read_bad_blocks (fs)) return 0; + HfsPrivateLinkExtent* l; last_bad = 0; - for (link = priv_data->bad_blocks_xtent_list; link; link = link->next) { - if ((unsigned int) PED_BE16_TO_CPU (link->extent.start_block) - + PED_BE16_TO_CPU (link->extent.block_count) > last_bad) - last_bad = PED_BE16_TO_CPU (link->extent.start_block) - + PED_BE16_TO_CPU (link->extent.block_count); + for (l = priv_data->bad_blocks_xtent_list; l; l = l->next) { + if ((unsigned int) PED_BE16_TO_CPU (l->extent.start_block) + + PED_BE16_TO_CPU (l->extent.block_count) > last_bad) + last_bad = PED_BE16_TO_CPU (l->extent.start_block) + + PED_BE16_TO_CPU (l->extent.block_count); } /* Count the free blocks from last_bad to the end of the volume */ diff --git a/libparted/fs/hfs/advfs_plus.c b/libparted/fs/hfs/advfs_plus.c index 94bfe3b..8543904 100644 --- a/libparted/fs/hfs/advfs_plus.c +++ b/libparted/fs/hfs/advfs_plus.c @@ -275,7 +275,6 @@ hfsplus_get_empty_end (const PedFileSystem *fs) HfsPPrivateFSData* priv_data = (HfsPPrivateFSData*) fs->type_specific; HfsPVolumeHeader* vh = priv_data->vh; - HfsPPrivateLinkExtent* link; unsigned int block, last_bad, end_free_blocks; /* find the next block to the last bad block of the volume */ @@ -287,12 +286,13 @@ hfsplus_get_empty_end (const PedFileSystem *fs) return 0; } + HfsPPrivateLinkExtent* l; last_bad = 0; - for (link = priv_data->bad_blocks_xtent_list; link; link = link->next) { - if ((unsigned int) PED_BE32_TO_CPU (link->extent.start_block) - + PED_BE32_TO_CPU (link->extent.block_count) > last_bad) - last_bad = PED_BE32_TO_CPU (link->extent.start_block) - + PED_BE32_TO_CPU (link->extent.block_count); + for (l = priv_data->bad_blocks_xtent_list; l; l = l->next) { + if ((unsigned int) PED_BE32_TO_CPU (l->extent.start_block) + + PED_BE32_TO_CPU (l->extent.block_count) > last_bad) + last_bad = PED_BE32_TO_CPU (l->extent.start_block) + + PED_BE32_TO_CPU (l->extent.block_count); } /* Count the free blocks from last_bad to the end of the volume */ -- 1.6.5.rc2.177.ga9dd6 >From 562e0007840f06f475b43bb81ffe81b238b627b5 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Wed, 30 Sep 2009 11:10:15 +0200 Subject: [PATCH 2/7] make PED_ASSERT handling sane: abort on false condition Upon a failed PED_ASSERT, Do not ask the interactive user if they want to continue. This change will affect any code that expects to be able to continue after a failed PED_ASSERT condition. However, such code is so fundamentally broken that this change is required. If you require to be able to continue after a false condition, then the code must not use a macro named like PED_ASSERT. This change was motivated by my desire to use the clang static analysis tool. Without this change, there were over 300 mostly-false-positive reports. With it, just 31, almost all legitimate. * libparted/debug.c (ped_assert): Remove first parameter. It is now tested via the macro. Now, this function always aborts, which helps clang understand. Do not ask the interactive user if s/he wants to continue. * include/parted/debug.h (PED_ASSERT): Test condition here, not in ped_assert. * libparted/disk.c (ped_disk_remove_partition): Remove the label that was used only upon failing PED_ASSERT. Now that PED_ASSERT always aborts for a false condition, that would have been dead code. (ped_disk_new_fresh): Likewise. --- include/parted/debug.h | 23 +++++++++++------------ libparted/debug.c | 17 +++++------------ libparted/disk.c | 10 ++-------- 3 files changed, 18 insertions(+), 32 deletions(-) diff --git a/include/parted/debug.h b/include/parted/debug.h index 4fcabb7..0195ac2 100644 --- a/include/parted/debug.h +++ b/include/parted/debug.h @@ -30,8 +30,9 @@ extern void ped_debug_set_handler (PedDebugHandler* handler); extern void ped_debug ( const int level, const char* file, int line, const char* function, const char* msg, ... ); -extern int ped_assert ( int cond, const char* cond_text, - const char* file, int line, const char* function ); +extern void __attribute__((__noreturn__)) +ped_assert ( const char* cond_text, + const char* file, int line, const char* function ); #if defined __GNUC__ && !defined __JSFTRACE__ @@ -41,14 +42,13 @@ extern int ped_assert ( int cond, const char* cond_text, #define PED_ASSERT(cond, action) \ do { \ - if (!ped_assert ( cond, \ + if (!(cond)) { \ + ped_assert ( \ #cond, \ __FILE__, \ __LINE__, \ - __PRETTY_FUNCTION__ )) \ - { \ - action; \ - } \ + __PRETTY_FUNCTION__ ); \ + } \ } while (0) #else /* !__GNUC__ */ @@ -65,14 +65,13 @@ static void PED_DEBUG (int level, ...) #define PED_ASSERT(cond, action) \ do { \ - if (!ped_assert ( cond, \ + if (!(cond)) { \ + ped_assert ( \ #cond, \ "unknown", \ 0, \ - "unknown" )) \ - { \ - action; \ - } \ + "unknown"); \ + } \ } while (0) #endif /* __GNUC__ */ diff --git a/libparted/debug.c b/libparted/debug.c index 564520a..86798c3 100644 --- a/libparted/debug.c +++ b/libparted/debug.c @@ -82,14 +82,9 @@ void ped_debug_set_handler ( PedDebugHandler* handler ) * Check an assertion. * Do not call this directly -- use PED_ASSERT() instead. */ -int ped_assert (int cond, const char* cond_text, - const char* file, int line, const char* function) +void ped_assert (const char* cond_text, + const char* file, int line, const char* function) { - PedExceptionOption opt; - - if (cond) - return 1; - #if HAVE_BACKTRACE /* Print backtrace stack */ void *stack[20]; @@ -108,14 +103,12 @@ int ped_assert (int cond, const char* cond_text, #endif /* Throw the exception */ - opt = ped_exception_throw ( + ped_exception_throw ( PED_EXCEPTION_BUG, - PED_EXCEPTION_IGNORE_CANCEL, + PED_EXCEPTION_FATAL, _("Assertion (%s) at %s:%d in function %s() failed."), cond_text, file, line, function); - - return (opt == PED_EXCEPTION_IGNORE); + abort (); } #endif /* DEBUG */ - diff --git a/libparted/disk.c b/libparted/disk.c index f3ad134..f3074a3 100644 --- a/libparted/disk.c +++ b/libparted/disk.c @@ -359,13 +359,11 @@ ped_disk_new_fresh (PedDevice* dev, const PedDiskType* type) if (!disk) goto error; _disk_pop_update_mode (disk); - PED_ASSERT (disk->update_mode == 0, goto error_destroy_disk); + PED_ASSERT (disk->update_mode == 0, ignored); disk->needs_clobber = 1; return disk; -error_destroy_disk: - ped_disk_destroy (disk); error: return NULL; } @@ -1849,15 +1847,11 @@ ped_disk_remove_partition (PedDisk* disk, PedPartition* part) PED_ASSERT (part != NULL, return 0); _disk_push_update_mode (disk); - PED_ASSERT (part->part_list == NULL, goto error); + PED_ASSERT (part->part_list == NULL, ignored); _disk_raw_remove (disk, part); _disk_pop_update_mode (disk); ped_disk_enumerate_partitions (disk); return 1; - -error: - _disk_pop_update_mode (disk); - return 0; } static int -- 1.6.5.rc2.177.ga9dd6 >From f439c4ebf68c77464c53473b939af7b1df9aa275 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Tue, 29 Sep 2009 21:29:00 +0200 Subject: [PATCH 3/7] maint: remove dead store code and declarations * libparted/labels/bsd.c (bsd_partition_set_flag): Remove dead store and corresponding decl. * libparted/arch/linux.c (init_ide): Likewise. (_dm_maptype): Likewise. (_mount_table_search): Likewise. * libparted/fs/amiga/asfs.c (_asfs_probe): Likewise. * libparted/labels/mac.c (mac_alloc_metadata): Likewise. * libparted/labels/rdb.c (amiga_write): Likewise. (amiga_write): Again. * libparted/fs/amiga/apfs.c (_generic_apfs_probe): Likewise. * libparted/fs/hfs/reloc_plus.c (hfsplus_effect_move_extent): Likewise. * libparted/fs/hfs/reloc.c (hfs_effect_move_extent): Likewise. * libparted/labels/dos.c (probe_partition_for_geom): Remove dead store in "can't happen" case. --- libparted/arch/linux.c | 12 +++--------- libparted/fs/amiga/apfs.c | 5 ++--- libparted/fs/amiga/asfs.c | 8 ++------ libparted/fs/hfs/reloc.c | 2 +- libparted/fs/hfs/reloc_plus.c | 2 +- libparted/labels/bsd.c | 2 -- libparted/labels/dos.c | 1 - libparted/labels/mac.c | 4 ---- libparted/labels/rdb.c | 7 +++---- 9 files changed, 12 insertions(+), 31 deletions(-) diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c index 52c31e2..52f7d21 100644 --- a/libparted/arch/linux.c +++ b/libparted/arch/linux.c @@ -408,7 +408,6 @@ _dm_maptype (PedDevice *dev) { LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev); struct dm_task *dmt; - void *next; uint64_t start, length; char *target_type = NULL; char *params; @@ -429,8 +428,7 @@ _dm_maptype (PedDevice *dev) if (!dm_task_run(dmt)) goto bad; - next = dm_get_next_target(dmt, NULL, &start, &length, - &target_type, ¶ms); + dm_get_next_target(dmt, NULL, &start, &length, &target_type, ¶ms); arch_specific->dmtype = strdup(target_type ? target_type : "NO-TARGET"); if (arch_specific->dmtype == NULL) @@ -741,7 +739,6 @@ init_ide (PedDevice* dev) { LinuxSpecific* arch_specific = LINUX_SPECIFIC (dev); struct stat dev_stat; - int dev_major; struct hd_driveid hdi; PedExceptionOption ex_status; char hdi_buf[41]; @@ -750,8 +747,6 @@ init_ide (PedDevice* dev) if (!_device_stat (dev, &dev_stat)) goto error; - dev_major = major (dev_stat.st_rdev); - if (!ped_device_open (dev)) goto error; @@ -2146,14 +2141,13 @@ _mount_table_search (const char* file_name, dev_t dev) char line[512]; char part_name[512]; FILE* file; - int junk; file = fopen (file_name, "r"); if (!file) return 0; while (fgets (line, 512, file)) { - junk = sscanf (line, "%s", part_name); - if (stat (part_name, &part_stat) == 0) { + if (sscanf (line, "%s", part_name) == 1 + && stat (part_name, &part_stat) == 0) { if (part_stat.st_rdev == dev) { fclose (file); return 1; diff --git a/libparted/fs/amiga/apfs.c b/libparted/fs/amiga/apfs.c index 41df426..0398794 100644 --- a/libparted/fs/amiga/apfs.c +++ b/libparted/fs/amiga/apfs.c @@ -44,19 +44,18 @@ _generic_apfs_probe (PedGeometry* geom, uint32_t kind) uint32_t *block; PedSector root; struct PartitionBlock * part; - uint32_t blocksize = 1, reserved = 2, prealloc = 0; + uint32_t blocksize = 1, reserved = 2; PED_ASSERT (geom != NULL, return NULL); PED_ASSERT (geom->dev != NULL, return NULL); - /* Finds the blocksize, prealloc and reserved values of the partition block */ + /* Finds the blocksize and reserved values of the partition block */ if (!(part = ped_malloc (PED_SECTOR_SIZE_DEFAULT*blocksize))) { ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, _("%s : Failed to allocate partition block\n"), __func__); goto error_part; } if (amiga_find_part(geom, part) != NULL) { - prealloc = PED_BE32_TO_CPU (part->de_PreAlloc); reserved = PED_BE32_TO_CPU (part->de_Reserved); blocksize = PED_BE32_TO_CPU (part->de_SizeBlock) * PED_BE32_TO_CPU (part->de_SectorPerBlock) / 128; diff --git a/libparted/fs/amiga/asfs.c b/libparted/fs/amiga/asfs.c index 7d5d2cb..0dfc27d 100644 --- a/libparted/fs/amiga/asfs.c +++ b/libparted/fs/amiga/asfs.c @@ -56,24 +56,20 @@ _asfs_probe (PedGeometry* geom) { uint32_t *block; struct PartitionBlock * part; - int blocksize = 1, reserved = 1, prealloc = 1; + int blocksize = 1; PedSector root; int found = 0; PED_ASSERT (geom != NULL, return NULL); PED_ASSERT (geom->dev != NULL, return NULL); - /* Finds the blocksize, prealloc and reserved values of the partition block */ + /* Finds the blocksize of the partition block */ if (!(part = ped_malloc (PED_SECTOR_SIZE_DEFAULT*blocksize))) { ped_exception_throw(PED_EXCEPTION_ERROR, PED_EXCEPTION_CANCEL, _("%s : Failed to allocate partition block\n"), __func__); goto error_part; } if (amiga_find_part(geom, part) != NULL) { - prealloc = PED_BE32_TO_CPU (part->de_PreAlloc) == 0 ? - 1 : PED_BE32_TO_CPU (part->de_PreAlloc); - reserved = PED_BE32_TO_CPU (part->de_Reserved) == 0 ? - 1 : PED_BE32_TO_CPU (part->de_Reserved); blocksize = PED_BE32_TO_CPU (part->de_SizeBlock) * PED_BE32_TO_CPU (part->de_SectorPerBlock) / 128; } diff --git a/libparted/fs/hfs/reloc.c b/libparted/fs/hfs/reloc.c index 8542678..2e7463a 100644 --- a/libparted/fs/hfs/reloc.c +++ b/libparted/fs/hfs/reloc.c @@ -55,7 +55,7 @@ hfs_effect_move_extent (PedFileSystem *fs, unsigned int *ptr_fblock, PED_ASSERT (hfs_block != NULL, return -1); PED_ASSERT (*ptr_to_fblock <= *ptr_fblock, return -1); /* quiet gcc */ - next_to_fblock = start = stop = 0; + start = stop = 0; /* Try to fit the extent AT or _BEFORE_ the wanted place, diff --git a/libparted/fs/hfs/reloc_plus.c b/libparted/fs/hfs/reloc_plus.c index 3309c1e..69ace77 100644 --- a/libparted/fs/hfs/reloc_plus.c +++ b/libparted/fs/hfs/reloc_plus.c @@ -59,7 +59,7 @@ hfsplus_effect_move_extent (PedFileSystem *fs, unsigned int *ptr_fblock, PED_ASSERT (hfsp_block != NULL, return -1); PED_ASSERT (*ptr_to_fblock <= *ptr_fblock, return -1); /* quiet GCC */ - next_to_fblock = start = stop = 0; + start = stop = 0; /* Try to fit the extent AT or _BEFORE_ the wanted place, diff --git a/libparted/labels/bsd.c b/libparted/labels/bsd.c index aef8e1a..54d13ee 100644 --- a/libparted/labels/bsd.c +++ b/libparted/labels/bsd.c @@ -476,7 +476,6 @@ bsd_partition_set_system (PedPartition* part, const PedFileSystemType* fs_type) static int bsd_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state) { - PedDisk* disk; // PedPartition* walk; // since -Werror, this unused variable would break build BSDPartitionData* bsd_data; @@ -485,7 +484,6 @@ bsd_partition_set_flag (PedPartition* part, PedPartitionFlag flag, int state) PED_ASSERT (part->disk != NULL, return 0); bsd_data = part->disk_specific; - disk = part->disk; switch (flag) { case PED_PARTITION_BOOT: diff --git a/libparted/labels/dos.c b/libparted/labels/dos.c index faee34d..cc9e0e3 100644 --- a/libparted/labels/dos.c +++ b/libparted/labels/dos.c @@ -616,7 +616,6 @@ probe_partition_for_geom (const PedPartition* part, PedCHSGeometry* bios_geom) head_size = ( A_ - C * cyl_size ) / H; else { /* should not happen because denum != 0 */ - head_size = 0; PED_ASSERT (0, return 0); } diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c index 15b2fd8..c8bf0d2 100644 --- a/libparted/labels/mac.c +++ b/libparted/labels/mac.c @@ -1569,14 +1569,10 @@ error: static int mac_alloc_metadata (PedDisk* disk) { - MacDiskData* mac_disk_data; - PED_ASSERT (disk != NULL, return 0); PED_ASSERT (disk->disk_specific != NULL, return 0); PED_ASSERT (disk->dev != NULL, return 0); - mac_disk_data = disk->disk_specific; - if (!add_metadata_part (disk, 0, disk->dev->sector_size / 512 - 1)) return 0; diff --git a/libparted/labels/rdb.c b/libparted/labels/rdb.c index a873771..1d21dbd 100644 --- a/libparted/labels/rdb.c +++ b/libparted/labels/rdb.c @@ -651,7 +651,7 @@ amiga_write (const PedDisk* disk) struct LinkedBlock *block; struct PartitionBlock *partition; PedPartition *part, *next_part; - PedSector cylblocks, first_hb, last_hb, last_used_hb; + PedSector cylblocks, first_hb, last_hb; uint32_t * table; uint32_t i; uint32_t rdb_num, part_num, block_num, next_num; @@ -681,7 +681,6 @@ amiga_write (const PedDisk* disk) (PedSector) PED_BE32_TO_CPU (rdb->rdb_Sectors); first_hb = (PedSector) PED_BE32_TO_CPU (rdb->rdb_RDBBlocksLo); last_hb = (PedSector) PED_BE32_TO_CPU (rdb->rdb_RDBBlocksHi); - last_used_hb = (PedSector) PED_BE32_TO_CPU (rdb->rdb_HighRDSKBlock); /* Allocate a free block table and initialize it. There must be room for at least RDB_NUM + 2 entries, since @@ -736,8 +735,8 @@ amiga_write (const PedDisk* disk) goto error_free_table; } - block_num = next_num = part_num = _amiga_next_free_block(table, rdb_num+1, - IDNAME_PARTITION); + block_num = part_num = _amiga_next_free_block(table, rdb_num+1, + IDNAME_PARTITION); part = _amiga_next_real_partition(disk, NULL); rdb->rdb_PartitionList = PED_CPU_TO_BE32(part ? part_num : LINK_END); for (; part != NULL; part = next_part, block_num = next_num) { -- 1.6.5.rc2.177.ga9dd6 >From df245df04056fe598b9eac8f136a09db061af8f1 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Tue, 29 Sep 2009 21:49:55 +0200 Subject: [PATCH 4/7] maint: remove more dead stores and fix a bug in do_mkpartfs * 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 >From c379d8935d25cc182e537527103252cdfeda6ef6 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Tue, 29 Sep 2009 22:02:56 +0200 Subject: [PATCH 5/7] maint: function returning "int", did not return a value. * parted/ui.c (init_readline): Return a value (always 0 for now). * parted/parted.c (_init): Handle init_readline's return value. --- parted/parted.c | 3 ++- parted/ui.c | 1 + 2 files changed, 3 insertions(+), 1 deletions(-) diff --git a/parted/parted.c b/parted/parted.c index 55627bf..0dd11d2 100644 --- a/parted/parted.c +++ b/parted/parted.c @@ -2461,7 +2461,8 @@ if (!_parse_options (argc_ptr, argv_ptr)) goto error_done_commands; if (!opt_script_mode) - init_readline (); + if (init_readline ()) + goto error_done_commands; #ifdef HAVE_GETUID if (getuid() != 0 && !opt_script_mode) { diff --git a/parted/ui.c b/parted/ui.c index 1fa10b7..295edba 100644 --- a/parted/ui.c +++ b/parted/ui.c @@ -1402,6 +1402,7 @@ init_readline (void) readline_state.in_readline = 0; } #endif + return 0; } int -- 1.6.5.rc2.177.ga9dd6 >From 8902061f1711c1bd95095abf5c4f7f7d07aac796 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Thu, 17 Sep 2009 14:15:01 +0200 Subject: [PATCH 6/7] build: use more gnulib modules for better POSIX compliance * bootstrap.conf (gnulib_modules): Add modules exposed via make CFLAGS=-DGNULIB_POSIXCHECK 2>&1 \ |perl -lne '/.* use gnulib module (\S+).*/ and print $1' \ |sort |uniq -c|sort -nr Add these: close fsync lseek mkstemp strdup unlink --- bootstrap.conf | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 8bf9c3f..d66f91d 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -28,9 +28,11 @@ gnulib_modules=" $avoided_gnulib_modules alloca announce-gen assert calloc config-h configmake + close closeout dirname fdl + fsync gettext git-version-gen gitlog-to-changelog @@ -39,15 +41,19 @@ gnulib_modules=" inttypes lib-ignore long-options + lseek malloc maintainer-makefile manywarnings + mkstemp mktempd realloc rpmatch progname safe-read stdbool + strdup + unlink update-copyright useless-if-before-free vc-list-files -- 1.6.5.rc2.177.ga9dd6 >From c0e17dae59f6b1c8f015c51bf71d479258d781a6 Mon Sep 17 00:00:00 2001 From: Jim Meyering <[email protected]> Date: Wed, 30 Sep 2009 11:42:32 +0200 Subject: [PATCH 7/7] maint: avoid false-positive NULL-deref warning from clang * parted/ui.c: Include <assert.h>. (command_line_get_disk): Add an assertion that command_line_get_device currently guarantees will always be true. This placates clang regarding its sole NULL-deref warning. (command_line_get_device): Move declarations "down" to first use. --- parted/ui.c | 11 +++++------ 1 files changed, 5 insertions(+), 6 deletions(-) diff --git a/parted/ui.c b/parted/ui.c index 295edba..c63df8a 100644 --- a/parted/ui.c +++ b/parted/ui.c @@ -28,6 +28,7 @@ #include <string.h> #include <unistd.h> #include <setjmp.h> +#include <assert.h> #include "command.h" #include "strlist.h" @@ -983,15 +984,12 @@ command_line_get_state (const char* prompt, int* value) int command_line_get_device (const char* prompt, PedDevice** value) { - char* def_dev_name = *value ? (*value)->path : NULL; - char* dev_name; - PedDevice* dev; - - dev_name = command_line_get_word (prompt, def_dev_name, NULL, 1); + char *def_dev_name = *value ? (*value)->path : NULL; + char *dev_name = command_line_get_word (prompt, def_dev_name, NULL, 1); if (!dev_name) return 0; - dev = ped_device_get (dev_name); + PedDevice *dev = ped_device_get (dev_name); free (dev_name); if (!dev) return 0; @@ -1008,6 +1006,7 @@ command_line_get_disk (const char* prompt, PedDisk** value) if (!command_line_get_device (prompt, &dev)) return 0; + assert (*value); if (dev != (*value)->dev) { PedDisk* new_disk = ped_disk_new (dev); if (!new_disk) -- 1.6.5.rc2.177.ga9dd6 _______________________________________________ parted-devel mailing list [email protected] http://lists.alioth.debian.org/mailman/listinfo/parted-devel

