Skip to content

Inconsistent use of 'ret' and error handling #4658

@ThalesBarretto

Description

@ThalesBarretto

If you do a 'make clang-check', currently there are some dead assignments reported, which i dig a bit into.

Usually we int ret = -1, use it to capture return values, do error handling.

But this pattern is inconsistent, and this uncovered some issues with error handling.

  • Capture the return value but skip error handling, neither return the error value:
/* api/src/glfs-handleops.c */
struct glfs_object *
pub_glfs_h_lookupat(struct glfs *fs, struct glfs_object *parent,
                    const char *path, struct stat *stat, int follow)
{
    int ret = 0;
(...)
    /* populate out args */
    if (!ret) {
        if (stat)
            glfs_iatt_to_stat(fs, &iatt, stat);
 
        ret = glfs_create_object(&loc, &object); /* <-- Value stored to 'ret' is never read */
    }
(....)
}
/* api/src/glfs-handleops.c */
  struct glfs_object *
  glfs_h_resolve_symlink(struct glfs *fs, struct glfs_object *object)
  {
(...)
    int ret = 0;
(...)
    if (ret == 0)
       ret = glfs_create_object(&sym_loc, &target_object); /* W: Variable 'ret' is assigned a value that is never used. */
(....)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions