[parted-devel] eliminating switch vs. enum warnings

Otavio Salvador otavio at debian.org
Thu Feb 15 23:45:41 CET 2007


Jim Meyering <jim at meyering.net> writes:

> A switch stmt like the above evokes a warning from gcc -Wall
> about FAT_TYPE_FAT12 not being handled.  One way to fix it
> is to add an "default:" case, making it equivalent, but warning-free:
>
> 	switch (fs_info->fat_type) {
> 		case FAT_TYPE_FAT16:
> 			return cluster * 2;
>
> 		case FAT_TYPE_FAT32:
> 			return cluster * 4;
>
> 		default:
> 			break;
> 	}
>
> But what if the FAT_TYPE_FAT12 case is a "can't-happen" case?
> Add a "PED_ASSERT(0, (void)0)"?
> or don't bother and just add the "default: break;"?

I think is better to raise the exception so if sometime in future we
fall there we'll know.

> So the above is one class of warned-about switch stmts.
> The other main one looks like this:
>
>         switch (ex_status) {
>                 case PED_EXCEPTION_CANCEL:
>                         goto error_close_dev;
>
>                 case PED_EXCEPTION_UNHANDLED:
>                         ped_exception_catch ();
>                 case PED_EXCEPTION_IGNORE:
>                         break;
>         }
>
> The problem is that there are numerous other PED_EXCEPTION_* symbols,
> yet they're essentially "can't happen" cases.  So use the
> "PED_ASSERT(0, (void)0)" again?  Or just "default: break;"?
>
>         switch (ex_status) {
>                 case PED_EXCEPTION_CANCEL:
>                         goto error_close_dev;
>
>                 case PED_EXCEPTION_UNHANDLED:
>                         ped_exception_catch ();
>                 case PED_EXCEPTION_IGNORE:
>                         break;
>                 default:
>                         break;
>         }
>
> My current patch takes the latter (perhaps more conservative)
> approach, but I can go the other way, too.

I think it's good to us be aware of what has been catch and then an
exception would help.

> I'll send the patch in the morning, after I go through it at least
> one more time.
>
> For now, here's a summary:
>
>  debug/clearfat/clearfat.c        |    5 +
>  libparted/arch/linux.c           |   26 ++++++----
>  libparted/cs/constraint.c        |    3 -
>  libparted/cs/geom.c              |    3 -
>  libparted/debug.c                |    6 --
>  libparted/disk.c                 |    5 -
>  libparted/filesys.c              |    3 -
>  libparted/fs/amiga/affs.c        |    3 -
>  libparted/fs/amiga/amiga.c       |   34 -------------
>  libparted/fs/amiga/apfs.c        |    3 -
>  libparted/fs/amiga/asfs.c        |    4 -
>  libparted/fs/ext2/ext2.c         |    3 -
>  libparted/fs/ext2/ext2_mkfs.c    |    3 -
>  libparted/fs/fat/bootsector.c    |    6 +-
>  libparted/fs/fat/calc.c          |    4 -
>  libparted/fs/fat/clstdup.c       |    3 -
>  libparted/fs/fat/count.c         |    7 +-
>  libparted/fs/fat/fat.c           |    3 -
>  libparted/fs/fat/resize.c        |   10 +++
>  libparted/fs/fat/table.c         |   30 +++++++++--
>  libparted/fs/fat/traverse.c      |    3 +
>  libparted/fs/hfs/file_plus.c     |   10 ++-
>  libparted/fs/hfs/hfs.c           |    9 +--
>  libparted/fs/hfs/hfs.h           |    3 -
>  libparted/fs/reiserfs/reiserfs.c |    9 +--
>  libparted/labels/aix.c           |    8 ---
>  libparted/labels/dos.c           |    6 --
>  libparted/labels/dvh.c           |   10 +--
>  libparted/labels/fdasd.c         |  101 ---------------------------------------
>  libparted/labels/gpt.c           |    6 --
>  libparted/labels/loop.c          |    4 -
>  libparted/labels/mac.c           |    5 -
>  libparted/labels/pc98.c          |    6 --
>  libparted/labels/sun.c           |    3 -
>  libparted/unit.c                 |    3 -
>  parted/parted.c                  |   52 +++++++-------------
>  parted/ui.c                      |    5 -
>  37 files changed, 124 insertions(+), 283 deletions(-)

Wow! Great work :-)

-- 
        O T A V I O    S A L V A D O R
---------------------------------------------
 E-mail: otavio at debian.org      UIN: 5906116
 GNU/Linux User: 239058     GPG ID: 49A5F855
 Home Page: http://otavio.ossystems.com.br
---------------------------------------------
"Microsoft sells you Windows ... Linux gives
 you the whole house."



More information about the parted-devel mailing list