#27 Incorrect use of enumeration type

closed-fixed
9
2001-02-06
2001-02-06
Anonymous
No

1) file_type() returns a value outside of the enumeration hostfs_file_type when an error occurs.

This isn't correct C - a compiler is allowed to chose any integer type capable of representing all the members of the enumeration. If the compiler happens to choose an unsigned type, the sign information of `-errno' is lost. (The compiler is even allowed to choose char, which isn't sufficiently large to store errno.) This probably is not what what intended, so I have replaced enum hostfs_file_type with an int in the patch, below. This hasn't caused a problem in practice since the error value from file_type is disregarded by get_inode.

--- um.org/fs/hostfs/hostfs.h Tue Feb 6 00:52:19 2001
+++ um/fs/hostfs/hostfs.h Mon Feb 5 22:01:04 2001
@@ -1,7 +1,9 @@
#ifndef __UM_FS_HOSTFS
#define __UM_FS_HOSTFS

-enum hostfs_file_type { HOSTFS_FILE, HOSTFS_DIR, HOSTFS_SYMLINK };
+#define HOSTFS_FILE 1
+#define HOSTFS_DIR 2
+#define HOSTFS_SYMLINK 3

/* These are exactly the same definitions as in fs.h, but the names are
* changed so that this file can be included in both kernel and user files.
@@ -39,7 +41,7 @@
int *blocks_out);
extern int access_file(char *path, int r, int w, int x);
extern int open_file(char *path, int r, int w);
-extern enum hostfs_file_type file_type(const char *path);
+extern int file_type(const char *path);
extern void *open_dir(char *path, int *err_out);
extern char *read_dir(void *stream, unsigned long long *pos, int *len_out);
extern void close_file(void *stream);
diff -x *.[oa] -x *.flags -x *~ -Nur um.org/fs/hostfs/hostfs_kern.c um/fs/hostfs/hostfs_kern.c
--- um.org/fs/hostfs/hostfs_kern.c Tue Feb 6 00:52:19 2001
+++ um/fs/hostfs/hostfs_kern.c Tue Feb 6 00:29:28 2001
@@ -327,7 +329,7 @@
int *error)
{
struct inode *inode;
- enum hostfs_file_type type;
+ int type;
char *new_path;
int err = 0, total = len;

diff -x *.[oa] -x *.flags -x *~ -Nur um.org/fs/hostfs/hostfs_user.c um/fs/hostfs/hostfs_user.c
--- um.org/fs/hostfs/hostfs_user.c Tue Feb 6 00:52:19 2001
+++ um/fs/hostfs/hostfs_user.c Tue Feb 6 00:30:19 2001
@@ -41,7 +41,7 @@
return(0);
}

-enum hostfs_file_type file_type(const char *path)
+int file_type(const char *path)
{
struct stat buf;

Discussion

  • Nobody/Anonymous

    Apologies for posting in the wrong category - I set the category field before splitting the bug report into this one and #131200.

     
  • Jeff Dike

    Jeff Dike - 2001-02-06
    • priority: 5 --> 9
    • assigned_to: nobody --> jdike
    • status: open --> closed-fixed
     
  • Jeff Dike

    Jeff Dike - 2001-02-06

    Nice spotting. Patch applied.

     
  • Jeff Dike

    Jeff Dike - 2001-02-06

    Nice spotting. Patch applied.

     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks