Ticket #3547: mc-3547-fish.c-cleanup-gcc-link-time-optimization-warning-v3.patch

File mc-3547-fish.c-cleanup-gcc-link-time-optimization-warning-v3.patch, 2.2 KB (added by and, 7 years ago)
  • src/vfs/fish/fish.c

    From 883b0038d94d580e1f46c9ad2fcb1df5724a922b Mon Sep 17 00:00:00 2001
    From: Andreas Mohr <and@gmx.li>
    Date: Fri, 1 Jan 2016 13:52:08 +0000
    Subject: [PATCH] fish.c: cleanup gcc link time optimization warning
    
    v3: sizeof() of malloc'd memory was wrong
    v2: consider andrew's comment
    
    will fix gcc LTO warning at:
      In function '__read_alias',
          inlined from 'fish_linear_abort.isra.0' at fish.c:1047:15:
      /usr/include/bits/unistd.h:39:9: error: call to '__read_chk_warn' declared with attribute warning: read called with bigger length than size of the destination buffer [-Werror]
         return __read_chk (__fd, __buf, __nbytes, __bos0 (__buf));
    
    Signed-off-by: Andreas Mohr <and@gmx.li>
    ---
     src/vfs/fish/fish.c | 22 +++++++++++++---------
     1 file changed, 13 insertions(+), 9 deletions(-)
    
    diff --git a/src/vfs/fish/fish.c b/src/vfs/fish/fish.c
    index 0cb5f30..6e7569d 100644
    a b fish_linear_abort (struct vfs_class *me, vfs_file_handler_t * fh) 
    10341034{ 
    10351035    fish_fh_data_t *fish = (fish_fh_data_t *) fh->data; 
    10361036    struct vfs_s_super *super = FH_SUPER; 
    1037     char buffer[BUF_8K]; 
     1037    char *buf; 
     1038    gsize bufsize = BUF_8K; 
    10381039    ssize_t n; 
    10391040 
    10401041    vfs_print_message ("%s", _("Aborting transfer...")); 
    10411042 
    1042     do 
     1043    buf = g_malloc (bufsize); 
     1044    while ((fish->total - fish->got) != 0) 
    10431045    { 
    1044         n = MIN ((off_t) sizeof (buffer), (fish->total - fish->got)); 
    1045         if (n != 0) 
     1046        if (bufsize > (gsize) (fish->total - fish->got)) 
    10461047        { 
    1047             n = read (SUP->sockr, buffer, n); 
    1048             if (n < 0) 
    1049                 return; 
    1050             fish->got += n; 
     1048           bufsize = (fish->total - fish->got); 
     1049           buf = g_try_realloc (buf, bufsize); 
    10511050        } 
     1051        n = read (SUP->sockr, buf, bufsize); 
     1052        if (n < 0) 
     1053            goto ret; 
     1054        fish->got += n; 
    10521055    } 
    1053     while (n != 0); 
    10541056 
    10551057    if (fish_get_reply (me, SUP->sockr, NULL, 0) != COMPLETE) 
    10561058        vfs_print_message ("%s", _("Error reported after abort.")); 
    10571059    else 
    10581060        vfs_print_message ("%s", _("Aborted transfer would be successful.")); 
     1061  ret: 
     1062    g_free(buf); 
    10591063} 
    10601064 
    10611065/* --------------------------------------------------------------------------------------------- */