[parted-devel] [PATCH] Compile warning-free with "gcc -Wall
-Wshadow".
Jim Meyering
jim at meyering.net
Mon Feb 12 23:35:30 CET 2007
Hello,
I find that keeping code warning-free (wrt gcc -Wall -Wshadow)
makes it easier to avoid certain classes of bugs.
Compiling with gcc -Wall -Wshadow evoked a few warnings
on a Debian/unstable system. Here are patches to fix those:
* libparted/exception.c (default_handler): Rename parameter "ex"
to "e", to avoid shadowing file-scoped global.
* libparted/fs/linux_swap/linux_swap.c (_generic_swap_probe): Add a
"can't happen" (with current callers) "default: goto error" clause
in a switch to avoid a may-be-used-uninitialized warning.
(_generic_swap_clobber): Likewise.
* libparted/fs/hfs/reloc_plus.c (hfsplus_pack_free_space_from_block):
Rename local variable "div" to "divisor", to avoid shadowing
the function in <stdlib.h>.
* libparted/fs/hfs/reloc.c (hfs_pack_free_space_from_block): Likewise.
* libparted/fs/hfs/cache.c (hfsc_cache_add_extent): Rename parameter
"index" to "ref_index" to avoid shadowing the <string.h> function.
* libparted/labels/sun.c (sun_partition_enumerate): Rename local
variable "i" to "j", to avoid shadowing another local.
Signed-off-by: Jim Meyering <jim at meyering.net>
---
libparted/exception.c | 14 +++++++-------
libparted/fs/hfs/cache.c | 4 ++--
libparted/fs/hfs/reloc.c | 8 ++++----
libparted/fs/hfs/reloc_plus.c | 8 ++++----
libparted/fs/linux_swap/linux_swap.c | 12 +++++++++---
libparted/labels/sun.c | 6 +++---
6 files changed, 29 insertions(+), 23 deletions(-)
diff --git a/libparted/exception.c b/libparted/exception.c
index 8b8b306..798e69c 100644
--- a/libparted/exception.c
+++ b/libparted/exception.c
@@ -1,6 +1,6 @@
/*
libparted - a library for manipulating disk partitions
- Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -126,9 +126,9 @@ ped_exception_get_option_string (PedExceptionOption ex_opt)
}
static PedExceptionOption
-default_handler (PedException* ex)
+default_handler (PedException* e)
{
- if (ex->type == PED_EXCEPTION_BUG)
+ if (e->type == PED_EXCEPTION_BUG)
fprintf (stderr,
_("A bug has been detected in GNU Parted. "
"Refer to the web site of parted "
@@ -141,14 +141,14 @@ default_handler (PedException* ex)
VERSION);
else
fprintf (stderr, "%s: ",
- ped_exception_get_type_string (ex->type));
- fprintf (stderr, "%s\n", ex->message);
+ ped_exception_get_type_string (e->type));
+ fprintf (stderr, "%s\n", e->message);
- switch (ex->options) {
+ switch (e->options) {
case PED_EXCEPTION_OK:
case PED_EXCEPTION_CANCEL:
case PED_EXCEPTION_IGNORE:
- return ex->options;
+ return e->options;
default:
return PED_EXCEPTION_UNHANDLED;
diff --git a/libparted/fs/hfs/cache.c b/libparted/fs/hfs/cache.c
index 8e4339c..22c4a3c 100644
--- a/libparted/fs/hfs/cache.c
+++ b/libparted/fs/hfs/cache.c
@@ -119,7 +119,7 @@ hfsc_delete_cache(HfsCPrivateCache* cache)
HfsCPrivateExtent*
hfsc_cache_add_extent(HfsCPrivateCache* cache, uint32_t start, uint32_t length,
uint32_t block, uint16_t offset, uint8_t sbb,
- uint8_t where, uint8_t index)
+ uint8_t where, uint8_t ref_index)
{
HfsCPrivateExtent* ext;
unsigned int idx = start >> CR_SHIFT;
@@ -160,7 +160,7 @@ hfsc_cache_add_extent(HfsCPrivateCache* cache, uint32_t start, uint32_t length,
ext->ref_offset = offset;
ext->sect_by_block = sbb;
ext->where = where;
- ext->ref_index = index;
+ ext->ref_index = ref_index;
ext->next = cache->linked_ref[idx];
cache->linked_ref[idx] = ext;
diff --git a/libparted/fs/hfs/reloc.c b/libparted/fs/hfs/reloc.c
index 1e70893..44bb82b 100644
--- a/libparted/fs/hfs/reloc.c
+++ b/libparted/fs/hfs/reloc.c
@@ -1,6 +1,6 @@
/*
libparted - a library for manipulating disk partitions
- Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -593,8 +593,8 @@ hfs_pack_free_space_from_block (PedFileSystem *fs, unsigned int fblock,
HfsCPrivateCache* cache;
unsigned int to_fblock = fblock;
unsigned int start = fblock;
- unsigned int div = PED_BE16_TO_CPU (mdb->total_blocks)
- + 1 - start - to_free;
+ unsigned int divisor = PED_BE16_TO_CPU (mdb->total_blocks)
+ + 1 - start - to_free;
int ret;
PED_ASSERT (!hfs_block, return 0);
@@ -654,7 +654,7 @@ hfs_pack_free_space_from_block (PedFileSystem *fs, unsigned int fblock,
fblock++;
}
- ped_timer_update(timer, (float)(to_fblock - start)/div);
+ ped_timer_update(timer, (float)(to_fblock - start)/divisor);
}
ped_free (hfs_block); hfs_block = NULL; hfs_block_count = 0;
diff --git a/libparted/fs/hfs/reloc_plus.c b/libparted/fs/hfs/reloc_plus.c
index 0a00253..6191e43 100644
--- a/libparted/fs/hfs/reloc_plus.c
+++ b/libparted/fs/hfs/reloc_plus.c
@@ -1,6 +1,6 @@
/*
libparted - a library for manipulating disk partitions
- Copyright (C) 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -866,8 +866,8 @@ hfsplus_pack_free_space_from_block (PedFileSystem *fs, unsigned int fblock,
HfsCPrivateCache* cache;
unsigned int to_fblock = fblock;
unsigned int start = fblock;
- unsigned int div = PED_BE32_TO_CPU (vh->total_blocks)
- + 1 - start - to_free;
+ unsigned int divisor = PED_BE32_TO_CPU (vh->total_blocks)
+ + 1 - start - to_free;
int ret;
PED_ASSERT (!hfsp_block, return 0);
@@ -929,7 +929,7 @@ hfsplus_pack_free_space_from_block (PedFileSystem *fs, unsigned int fblock,
fblock++;
}
- ped_timer_update(timer, (float)(to_fblock - start) / div);
+ ped_timer_update(timer, (float)(to_fblock - start) / divisor);
}
ped_free (hfsp_block); hfsp_block = NULL; hfsp_block_count = 0;
diff --git a/libparted/fs/linux_swap/linux_swap.c b/libparted/fs/linux_swap/linux_swap.c
index d3faea6..d57db00 100644
--- a/libparted/fs/linux_swap/linux_swap.c
+++ b/libparted/fs/linux_swap/linux_swap.c
@@ -1,6 +1,6 @@
/*
libparted - a library for manipulating disk partitions
- Copyright (C) 1999, 2000, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2002, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -93,12 +93,15 @@ _generic_swap_probe (PedGeometry* geom, int kind)
break;
/* Check for new style swap partitions. */
case 1:
- fs = _swap_v2_open(geom);
+ fs = _swap_v2_open(geom);
break;
/* Check for swap partitions containing swsusp data. */
case -1:
fs = _swap_swsusp_open(geom);
break;
+
+ default:
+ goto error; /* Not reached */
}
if (!fs)
@@ -136,12 +139,15 @@ _generic_swap_clobber (PedGeometry* geom, int kind)
break;
/* Check for new style swap partitions. */
case 1:
- fs = _swap_v2_open(geom);
+ fs = _swap_v2_open(geom);
break;
/* Check for swap partitions containing swsusp data. */
case -1:
fs = _swap_swsusp_open(geom);
break;
+
+ default:
+ goto error; /* Not reached */
}
if (!fs)
diff --git a/libparted/labels/sun.c b/libparted/labels/sun.c
index e5aa6fb..253f317 100644
--- a/libparted/labels/sun.c
+++ b/libparted/labels/sun.c
@@ -1,7 +1,7 @@
/* -*- Mode: c; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
libparted - a library for manipulating disk partitions
- Copyright (C) 2000, 2001, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2000, 2001, 2005, 2007 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -728,7 +728,7 @@ sun_partition_enumerate (PedPartition* part)
/* Ok, now allocate the Whole disk if it isn't already */
p = ped_disk_get_partition (part->disk, WHOLE_DISK_PART + 1);
if (!p) {
- int i = ped_exception_throw (
+ int j = ped_exception_throw (
PED_EXCEPTION_WARNING,
PED_EXCEPTION_IGNORE_CANCEL,
_("The Whole Disk partition is the only "
@@ -737,7 +737,7 @@ sun_partition_enumerate (PedPartition* part)
"a real one. Solaris may not be able to "
"boot without it, and SILO (the sparc boot "
"loader) appreciates it as well."));
- if (i == PED_EXCEPTION_IGNORE) {
+ if (j == PED_EXCEPTION_IGNORE) {
/* bad bad bad...you will suffer your own fate */
part->num = WHOLE_DISK_PART + 1;
return 1;
--
1.5.0.rc4.26.gcc46a-dirty
More information about the parted-devel
mailing list