Ticket #2033: 2033-Unneeded-goto-in-lib-vfs-mc-vfs-extfs.c.patch

File 2033-Unneeded-goto-in-lib-vfs-mc-vfs-extfs.c.patch, 6.3 KB (added by vit_r, 14 years ago)

Unneeded-goto-in-lib-vfs-mc-vfs-extfs.c

  • lib/vfs/mc-vfs/extfs.c

    From f5049d3a4cb2efecff125d13d98b370673196373 Mon Sep 17 00:00:00 2001
    From: Vit Rosin <vit_r@list.ru>
    Date: Wed, 17 Feb 2010 13:38:26 +0000
    Subject: [PATCH]  Unneeded goto in lib/vfs/mc-vfs/extfs.c
    
    ---
     lib/vfs/mc-vfs/extfs.c |   98 +++++++++++++++++++++++++----------------------
     1 files changed, 52 insertions(+), 46 deletions(-)
    
    diff --git a/lib/vfs/mc-vfs/extfs.c b/lib/vfs/mc-vfs/extfs.c
    index a8f086c..5cca9ef 100644
    a b extfs_stat_move (struct stat *buf, const struct inode *inode) 
    959959    buf->st_ctime = inode->ctime; 
    960960} 
    961961 
     962 
     963static int 
     964free_mpath (char **mpath, const int retval) 
     965{ 
     966    g_free (*mpath); 
     967    *mpath = NULL; 
     968    return retval; 
     969} 
     970 
    962971static int 
    963972extfs_internal_stat (struct vfs_class *me, const char *path, struct stat *buf, 
    964973                     gboolean resolve) 
    extfs_internal_stat (struct vfs_class *me, const char *path, struct stat *buf, 
    966975    struct archive *archive; 
    967976    char *q, *mpath; 
    968977    struct entry *entry; 
    969     int result = -1; 
    970978 
    971979    mpath = g_strdup (path); 
     980    if (mpath == NULL) 
     981        return (-1); 
    972982 
    973983    q = extfs_get_path_mangle (me, mpath, &archive, FALSE); 
    974984    if (q == NULL) 
    975         goto cleanup; 
     985        return free_mpath (&mpath, (-1)); 
    976986    entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); 
    977987    if (entry == NULL) 
    978         goto cleanup; 
     988        return free_mpath (&mpath, (-1)); 
    979989    if (resolve) { 
    980990        entry = extfs_resolve_symlinks (entry); 
    981991        if (entry == NULL) 
    982             goto cleanup; 
     992            return free_mpath (&mpath, (-1)); 
    983993    } 
    984994    extfs_stat_move (buf, entry->inode); 
    985     result = 0; 
    986 cleanup: 
    987     g_free (mpath); 
    988     return result; 
     995    return free_mpath (&mpath, 0); 
    989996} 
    990997 
    991998static int 
    extfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size) 
    10191026    int result = -1; 
    10201027 
    10211028    mpath = g_strdup (path); 
     1029    if (mpath == NULL) 
     1030        return (-1); 
    10221031 
    10231032    q = extfs_get_path_mangle (me, mpath, &archive, FALSE); 
    10241033    if (q  == NULL) 
    1025         goto cleanup; 
     1034        return free_mpath (&mpath, result); 
    10261035    entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); 
    10271036    if (entry == NULL) 
    1028         goto cleanup; 
     1037        return free_mpath (&mpath, result); 
    10291038    if (!S_ISLNK (entry->inode->mode)) { 
    10301039        me->verrno = EINVAL; 
    1031         goto cleanup; 
     1040        return free_mpath (&mpath, result); 
    10321041    } 
    10331042    len = strlen (entry->inode->linkname); 
    10341043    if (size < len) 
    extfs_readlink (struct vfs_class *me, const char *path, char *buf, size_t size) 
    10361045    /* readlink() does not append a NUL character to buf */ 
    10371046    result = len; 
    10381047    memcpy (buf, entry->inode->linkname, result); 
    1039 cleanup: 
    1040     g_free (mpath); 
    1041     return result; 
     1048    return free_mpath (&mpath, result); 
    10421049} 
    10431050 
    10441051static int 
    extfs_unlink (struct vfs_class *me, const char *file) 
    10751082    struct archive *archive; 
    10761083    char *q, *mpath; 
    10771084    struct entry *entry; 
    1078     int result = -1; 
    10791085 
    10801086    mpath = g_strdup (file); 
     1087    if (mpath == NULL) 
     1088        return (-1); 
    10811089 
    10821090    q = extfs_get_path_mangle (me, mpath, &archive, FALSE); 
    10831091    if (q == NULL) 
    1084         goto cleanup; 
     1092        return free_mpath (&mpath, (-1)); 
    10851093    entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); 
    10861094    if (entry == NULL) 
    1087         goto cleanup; 
     1095        return free_mpath (&mpath, (-1)); 
    10881096    entry = extfs_resolve_symlinks (entry); 
    10891097    if (entry == NULL) 
    1090         goto cleanup; 
     1098        return free_mpath (&mpath, (-1)); 
    10911099    if (S_ISDIR (entry->inode->mode)) { 
    10921100        me->verrno = EISDIR; 
    1093         goto cleanup; 
     1101        return free_mpath (&mpath, (-1)); 
    10941102    } 
    10951103    if (extfs_cmd (" rm ", archive, entry, "")) { 
    10961104        my_errno = EIO; 
    1097         goto cleanup; 
     1105        return free_mpath (&mpath, (-1)); 
    10981106    } 
    10991107    extfs_remove_entry (entry); 
    1100     result = 0; 
    1101 cleanup: 
    1102     g_free (mpath); 
    1103     return result; 
     1108    return free_mpath (&mpath, 0); 
    11041109} 
    11051110 
    11061111static int 
    extfs_mkdir (struct vfs_class *me, const char *path, mode_t mode) 
    11091114    struct archive *archive; 
    11101115    char *q, *mpath; 
    11111116    struct entry *entry; 
    1112     int result = -1; 
    11131117 
    11141118    (void) mode; 
    11151119 
    11161120    mpath = g_strdup (path); 
     1121    if (mpath == NULL) 
     1122        return (-1); 
    11171123 
    11181124    q = extfs_get_path_mangle (me, mpath, &archive, FALSE); 
    11191125    if (q == NULL) 
    1120         goto cleanup; 
     1126        return free_mpath (&mpath, (-1)); 
     1127 
    11211128    entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); 
    11221129    if (entry != NULL) { 
    11231130        me->verrno = EEXIST; 
    1124         goto cleanup; 
     1131        return free_mpath (&mpath, (-1)); 
    11251132    } 
    11261133    entry = extfs_find_entry (archive->root_entry, q, TRUE, FALSE); 
    11271134    if (entry == NULL) 
    1128         goto cleanup; 
     1135        return free_mpath (&mpath, (-1)); 
     1136 
    11291137    entry = extfs_resolve_symlinks (entry); 
    11301138    if (entry == NULL) 
    1131         goto cleanup; 
     1139        return free_mpath (&mpath, (-1)); 
     1140 
    11321141    if (!S_ISDIR (entry->inode->mode)) { 
    11331142        me->verrno = ENOTDIR; 
    1134         goto cleanup; 
     1143        return free_mpath (&mpath, (-1)); 
    11351144    } 
    11361145 
    11371146    if (extfs_cmd (" mkdir ", archive, entry, "")) { 
    11381147        my_errno = EIO; 
    11391148        extfs_remove_entry (entry); 
    1140         goto cleanup; 
     1149        return free_mpath (&mpath, (-1)); 
    11411150    } 
    1142     result = 0; 
    1143 cleanup: 
    1144     g_free (mpath); 
    1145     return result; 
     1151    return free_mpath (&mpath, 0); 
    11461152} 
    11471153 
    11481154static int 
    extfs_rmdir (struct vfs_class *me, const char *path) 
    11511157    struct archive *archive; 
    11521158    char *q, *mpath; 
    11531159    struct entry *entry; 
    1154     int result = -1; 
    11551160 
    11561161    mpath = g_strdup (path); 
     1162    if (mpath == NULL) 
     1163        return (-1); 
    11571164 
    11581165    q = extfs_get_path_mangle (me, mpath, &archive, FALSE); 
    11591166    if (q == NULL) 
    1160         goto cleanup; 
     1167        return free_mpath (&mpath, (-1)); 
     1168 
    11611169    entry = extfs_find_entry (archive->root_entry, q, FALSE, FALSE); 
    11621170    if (entry == NULL) 
    1163         goto cleanup; 
     1171        return free_mpath (&mpath, (-1)); 
     1172 
    11641173    entry = extfs_resolve_symlinks (entry); 
    11651174    if (entry == NULL) 
    1166         goto cleanup; 
     1175        return free_mpath (&mpath, (-1)); 
     1176 
    11671177    if (!S_ISDIR (entry->inode->mode)) { 
    11681178        me->verrno = ENOTDIR; 
    1169         goto cleanup; 
     1179        return free_mpath (&mpath, (-1)); 
    11701180    } 
    1171  
    11721181    if (extfs_cmd (" rmdir ", archive, entry, "")) { 
    11731182        my_errno = EIO; 
    1174         goto cleanup; 
     1183        return free_mpath (&mpath, (-1)); 
    11751184    } 
    11761185    extfs_remove_entry (entry); 
    1177     result = 0; 
    1178 cleanup: 
    1179     g_free (mpath); 
    1180     return result; 
     1186    return free_mpath (&mpath, 0); 
    11811187} 
    11821188 
    11831189static int