Ticket #2043: 2043-g_strdup-of-_vfs_get_cwd.patch

File 2043-g_strdup-of-_vfs_get_cwd.patch, 2.7 KB (added by vit_r, 10 years ago)

g_strdup of _vfs_get_cwd ()

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

    From 393792ff424dea52c46666c63502932f2da499e5 Mon Sep 17 00:00:00 2001
    From: Vit Rosin <vit_r@list.ru>
    Date: Sat, 20 Feb 2010 17:54:23 +0000
    Subject: [PATCH]  g_strdup of _vfs_get_cwd ()
         as it is mentioned in lib/vfs/mc-vfs/vfs.c just before _vfs_get_cwd ()
         {{{
               You must g_strdup() whatever this function returns.
         }}}
    
        and a little bit alignments
    ---
     lib/vfs/mc-vfs/vfs.c |   29 ++++++++++++++++-------------
     1 files changed, 16 insertions(+), 13 deletions(-)
    
    diff --git a/lib/vfs/mc-vfs/vfs.c b/lib/vfs/mc-vfs/vfs.c
    index 3f92269..1e7f71d 100644
    a b vfs_split (char *path, char **inpath, char **op) 
    305305    if (slash) 
    306306        *slash = 0; 
    307307 
    308     if ((ret = vfs_prefix_to_class (semi+1))){ 
    309         if (op)  
     308    ret = vfs_prefix_to_class (semi + 1); 
     309    if (ret) { 
     310        if (op) 
    310311            *op = semi + 1; 
    311312        if (inpath) 
    312313            *inpath = slash ? slash + 1 : NULL; 
    mc_open (const char *filename, int flags, ...) 
    559560 
    560561    info = (*vfs->open) (vfs, file, flags, mode);       /* open must be supported */ 
    561562    g_free (file); 
    562     if (!info){ 
     563    if (!info) { 
    563564        errno = ferrno (vfs); 
    564565        return -1; 
    565566    } 
    _vfs_get_cwd (void) 
    947948                if (!sys_cwd) 
    948949                    return current_dir; 
    949950 
    950         /* Otherwise check if it is O.K. to use the current_dir */ 
    951                 if (!cd_symlinks || mc_stat (sys_cwd, &my_stat)  
    952             || mc_stat (current_dir, &my_stat2) 
    953             || my_stat.st_ino != my_stat2.st_ino 
    954             || my_stat.st_dev != my_stat2.st_dev) { 
    955             g_free (current_dir); 
     951                /* Otherwise check if it is O.K. to use the current_dir */ 
     952                if (!cd_symlinks || mc_stat (sys_cwd, &my_stat) 
     953                    || mc_stat (current_dir, &my_stat2) 
     954                    || my_stat.st_ino != my_stat2.st_ino  
     955                    || my_stat.st_dev != my_stat2.st_dev) { 
     956                    g_free (current_dir); 
    956957                    current_dir = sys_cwd; 
    957958                    return sys_cwd; 
    958                      }/* Otherwise we return current_dir below */ 
     959                } /* Otherwise we return current_dir below */ 
    959960            } 
    960     } 
     961        } 
    961962    } 
    962963    g_free (trans); 
    963964    return current_dir; 
    vfs_setup_wd (void) 
    982983char * 
    983984mc_get_current_wd (char *buffer, int size) 
    984985{ 
    985     const char *cwd = _vfs_get_cwd (); 
     986    const char *cwd = g_strdup (_vfs_get_cwd ()); 
     987    if (cwd == NULL) 
     988        return NULL; 
    986989 
    987990    g_strlcpy (buffer, cwd, size); 
    988991    return buffer; 
    vfs_canon (const char *path) 
    10281031        vfs_die("Cannot canonicalize NULL"); 
    10291032 
    10301033    /* Relative to current directory */ 
    1031     if (*path != PATH_SEP){  
     1034    if (*path != PATH_SEP) {  
    10321035        char *local, *result; 
    10331036 
    10341037        local = concat_dir_and_file (current_dir, path);