Ticket #2097: 2097-getting-rid-of-else_return-in-mc-4.7.1.diff

File 2097-getting-rid-of-else_return-in-mc-4.7.1.diff, 6.9 KB (added by vit_r, 14 years ago)
  • lib/vfs/mc-vfs/fish.c

    diff -urN mc-4.7.1-old/lib/vfs/mc-vfs/fish.c mc-4.7.1-new/lib/vfs/mc-vfs/fish.c
    old new  
    128128 
    129129        if (strncmp(answer, "### ", 4)) { 
    130130            was_garbage = 1; 
    131             if (string_buf) 
     131            if (string_buf != NULL) { 
    132132                g_strlcpy(string_buf, answer, string_len); 
    133         } else return fish_decode_reply(answer+4, was_garbage); 
     133            } 
     134        } else { 
     135            return fish_decode_reply (answer + 4, was_garbage); 
     136        } 
    134137    } 
    135138} 
    136139 
  • lib/vfs/mc-vfs/vfs.c

    diff -urN mc-4.7.1-old/lib/vfs/mc-vfs/vfs.c mc-4.7.1-new/lib/vfs/mc-vfs/vfs.c
    old new  
    537537{ 
    538538    int  mode; 
    539539    void *info; 
    540     va_list ap; 
     540    struct vfs_class *vfs; 
     541 
     542    file = vfs_canon_and_translate (filename); 
     543    if (file == NULL) 
     544        return -1; 
    541545 
    542     char *file = vfs_canon_and_translate (filename); 
    543     if (file != NULL) { 
    544     struct vfs_class *vfs = vfs_get_class (file); 
     546    vfs = vfs_get_class (file); 
    545547 
    546548    /* Get the mode flag */ 
    547549    if (flags & O_CREAT) { 
    548         va_start (ap, flags); 
     550        va_list ap; 
     551        va_start (ap, flags);  
    549552        mode = va_arg (ap, int); 
    550553        va_end (ap); 
    551     } else 
     554    } else { 
    552555        mode = 0; 
    553      
    554     if (!vfs->open) { 
     556    } 
     557    if (vfs->open == NULL) { 
    555558        g_free (file); 
    556559        errno = -EOPNOTSUPP; 
    557560        return -1; 
    558561    } 
    559  
    560562    info = (*vfs->open) (vfs, file, flags, mode);       /* open must be supported */ 
    561563    g_free (file); 
    562     if (!info){ 
     564    if (info == NULL) { 
    563565        errno = ferrno (vfs); 
    564566        return -1; 
    565567    } 
    566  
    567568    return vfs_new_handle (vfs, info); 
    568     } else return -1; 
    569569} 
    570570 
    571571 
     
    575575    struct vfs_class *vfs; \ 
    576576    int result; \ 
    577577    char *mpath = vfs_canon_and_translate (path); \ 
    578     if (mpath != NULL) { \ 
     578    if (mpath == NULL) \ 
     579        return -1; \ 
    579580    vfs = vfs_get_class (mpath); \ 
    580581    if (vfs == NULL){ \ 
    581582        g_free (mpath); \ 
     
    586587    if (result == -1) \ 
    587588        errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \ 
    588589    return result; \ 
    589     } else return -1; \ 
    590590} 
    591591 
    592592MC_NAMEOP (chmod, (const char *path, mode_t mode), (vfs, mpath, mode)) 
     
    608608    char *tmp; 
    609609     
    610610    mpath = vfs_canon_and_translate (path);  
    611     if (mpath != NULL) { 
    612         tmp = g_strdup (name1); 
    613         lpath = vfs_translate_path_n (tmp); 
    614         g_free (tmp); 
    615      
    616         if (lpath != NULL) { 
    617             vfs = vfs_get_class (mpath);  
    618             result = vfs->symlink ? (*vfs->symlink) (vfs, lpath, mpath) : -1; 
    619             g_free (lpath); 
    620             g_free (mpath); 
    621  
    622             if (result == -1)  
    623                 errno = vfs->symlink ? ferrno (vfs) : E_NOTSUPP;  
    624             return result;  
    625         }  
    626         g_free (mpath);  
     611    if (mpath == NULL) 
     612        return -1; 
     613 
     614    tmp = g_strdup (name1); 
     615    lpath = vfs_translate_path_n (tmp); 
     616    g_free (tmp); 
     617 
     618    if (lpath == NULL) { 
     619        g_free (mpath); 
     620        return -1; 
    627621    } 
    628     return -1; 
     622    vfs = vfs_get_class (mpath);  
     623    result = vfs->symlink ? (*vfs->symlink) (vfs, lpath, mpath) : -1; 
     624    g_free (mpath); 
     625    g_free (lpath); 
     626 
     627    if (result == -1)  
     628        errno = vfs->symlink ? ferrno (vfs) : E_NOTSUPP;  
     629     
     630    return result; 
    629631} 
    630632 
    631633#define MC_HANDLEOP(name, inarg, callarg) \ 
     
    655657    int result; \ 
    656658    char *name2, *name1; \ 
    657659    name1 = vfs_canon_and_translate (fname1); \ 
    658     if (name1 != NULL) { \ 
    659         name2 = vfs_canon_and_translate (fname2); \ 
    660         if (name2 != NULL) { \ 
     660    if (name1 == NULL) \ 
     661        return -1; \ 
     662    name2 = vfs_canon_and_translate (fname2); \ 
     663    if (name2 == NULL) { \ 
     664        g_free (name1); \ 
     665        return -1; \ 
     666    } \ 
    661667    vfs = vfs_get_class (name1); \ 
    662668    if (vfs != vfs_get_class (name2)){ \ 
    663669        errno = EXDEV; \ 
     
    671677    if (result == -1) \ 
    672678        errno = vfs->name ? ferrno (vfs) : E_NOTSUPP; \ 
    673679    return result; \ 
    674     } else { \ 
    675         g_free (name1); \ 
    676         return -1; \ 
    677     } \ 
    678     } else return -1; \ 
    679680} 
    680681 
    681682MC_RENAMEOP (link) 
     
    704705        vfs_die("You don't want to pass NULL to mc_setctl."); 
    705706     
    706707    mpath = vfs_canon_and_translate (path); 
    707     if (mpath != NULL) { 
     708    if (mpath == NULL) 
     709        return -1; 
     710 
    708711    vfs = vfs_get_class (mpath); 
    709712    result = vfs->setctl ? (*vfs->setctl)(vfs, mpath, ctlop, arg) : 0; 
    710713    g_free (mpath); 
    711714    return result; 
    712     } else return -1; 
    713715} 
    714716 
    715717int 
     
    752754    canon = vfs_canon (dirname); 
    753755    dname = vfs_translate_path_n (canon); 
    754756 
    755     if (dname != NULL) { 
     757    if (dname == NULL) { 
     758        g_free (canon); 
     759        return NULL; 
     760    } 
    756761        vfs = vfs_get_class (dname); 
    757762        info = vfs->opendir ? (*vfs->opendir)(vfs, dname) : NULL; 
    758763        g_free (dname); 
     
    777782        handlep = g_new (int, 1); 
    778783        *handlep = handle; 
    779784        return (DIR *) handlep; 
    780     } else { 
    781         g_free (canon); 
    782         return NULL; 
    783     } 
    784785} 
    785786 
    786787static struct dirent * mc_readdir_result = NULL; 
     
    10701071 
    10711072    new_dir = vfs_canon (path); 
    10721073    trans_dir = vfs_translate_path_n (new_dir); 
    1073     if (trans_dir != NULL) { 
    1074         new_vfs = vfs_get_class (trans_dir); 
     1074    if (trans_dir == NULL) { 
     1075        g_free (new_dir); 
     1076        return -1; 
     1077    } 
     1078    new_vfs = vfs_get_class (trans_dir); 
    10751079    if (!new_vfs->chdir) { 
    10761080        g_free (new_dir); 
    10771081            g_free (trans_dir); 
     
    11081112 
    11091113        g_free (trans_dir); 
    11101114    return 0; 
    1111     } else { 
    1112         g_free (new_dir); 
    1113         return -1; 
    1114     } 
    11151115} 
    11161116 
    11171117/* Return 1 is the current VFS class is local */ 
     
    11291129    char *fname; 
    11301130 
    11311131    fname = vfs_canon_and_translate (filename); 
    1132     if (fname != NULL) { 
     1132    if (fname == NULL) 
     1133        return -1; 
     1134 
    11331135    vfs = vfs_get_class (fname); 
    11341136    g_free (fname); 
    11351137    return vfs->flags; 
    1136     } else return -1; 
    11371138} 
    11381139 
    11391140static char * 
     
    11871188{ 
    11881189    char *result; 
    11891190    char *path; 
     1191    struct vfs_class *vfs; 
    11901192             
    11911193    path = vfs_canon_and_translate (pathname); 
    1192     if (path != NULL) { 
    1193     struct vfs_class *vfs = vfs_get_class (path);     
     1194    if (path == NULL) 
     1195        return NULL; 
     1196         
     1197    vfs = vfs_get_class (path); 
    11941198 
    11951199    result = vfs->getlocalcopy ? (*vfs->getlocalcopy)(vfs, path) : 
    11961200                                 mc_def_getlocalcopy (path); 
     
    11981202    if (!result) 
    11991203        errno = ferrno (vfs); 
    12001204    return result; 
    1201     } else return NULL; 
    12021205} 
    12031206 
    12041207static int 
     
    12531256{ 
    12541257    int return_value = 0; 
    12551258    char *path; 
     1259    struct vfs_class *vfs; 
    12561260     
    12571261    path = vfs_canon_and_translate (pathname); 
    1258     if (path != NULL) { 
    1259     struct vfs_class *vfs = vfs_get_class (path); 
     1262    if (path == NULL) 
     1263        return -1; 
     1264         
     1265    vfs = vfs_get_class (path); 
    12601266 
    12611267    return_value = vfs->ungetlocalcopy ?  
    12621268            (*vfs->ungetlocalcopy)(vfs, path, local, has_changed) : 
    12631269            mc_def_ungetlocalcopy (vfs, path, local, has_changed); 
    12641270    g_free (path); 
    12651271    return return_value; 
    1266     } else return -1; 
    12671272} 
    12681273 
    12691274