Ignore:
Timestamp:
May 6, 2014, 10:24:12 AM (6 years ago)
Author:
Bruno Cornec
Message:
  • Improve again memory management: remove some strcat calls change function percent_media_full_comment to return a dynamically allocated string
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/3.2/mondo/src/common/libmondo-string.c

    r3205 r3288  
    472472 * @param value The value to replace @p token.
    473473 */
     474
     475/* TODO: consider mr_strtok */
    474476void resolve_naff_tokens(char *output, char *ip, char *value, char *token)
    475477{
     
    10201022    /*@ int *********************************************** */
    10211023    int percentage;
    1022     int j;
    10231024
    10241025    /*@ buffers ******************************************* */
    1025     static char outstr[MAX_STR_LEN];
     1026    char * outstr = NULL;
    10261027    char *pos_w_commas = NULL;
    10271028    char *mds = NULL;
     
    10341035        mr_asprintf(pos_w_commas, "%s", commarize(tmp));
    10351036        mr_free(tmp);
    1036         sprintf(outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas);
     1037        mr_asprintf(outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas);
    10371038        mr_free(pos_w_commas);
    10381039        return (outstr);
     
    10451046            percentage = 100;
    10461047        }
    1047         sprintf(outstr, "Volume %d: [", g_current_media_number);
     1048        mr_asprintf(outstr, "Volume %d: [", g_current_media_number);
    10481049    } else {
    10491050        percentage = (int) (space_occupied_by_cd(bkpinfo->scratchdir) * 100 / 1024 / bkpinfo->media_size);
    10501051        mds = media_descriptor_string(bkpinfo->backup_media_type);
    1051         sprintf(outstr, "%s %d: [", mds, g_current_media_number);
     1052        mr_asprintf(outstr, "%s %d: [", mds, g_current_media_number);
    10521053        mr_free(mds);
    10531054    }
    10541055    for (j = 0; j < percentage; j += 5) {
    1055         strcat(outstr, "*");
     1056        mr_strcat(outstr, "*");
    10561057    }
    10571058    for (; j < 100; j += 5) {
    1058         strcat(outstr, ".");
    1059     }
    1060     j = (int) strlen(outstr);
    1061     sprintf(outstr + j, "] %d%% used", percentage);
     1059        mr_strcat(outstr, ".");
     1060    }
     1061    mr_strcat(outstr, "] %d%% used", percentage);
    10621062    return (outstr);
    10631063}
     1064
    10641065
    10651066/**
Note: See TracChangeset for help on using the changeset viewer.