Changeset 3611 for branches


Ignore:
Timestamp:
Nov 10, 2016, 9:09:54 PM (3 years ago)
Author:
bruno
Message:

Remove more static allocation

Location:
branches/3.2/mondo/src
Files:
6 edited

Legend:

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

    r3610 r3611  
    11161116    /*@ buffers *************** */
    11171117    char *tmp = NULL;
     1118    char *tmp1 = NULL;
    11181119    char *mds = NULL;
    11191120
     
    11421143        scratchLL++;
    11431144    }
     1145    tmp1 = number_to_text((int) (scratchLL + 1));
    11441146    if (scratchLL <= 1) {
    11451147        mds = media_descriptor_string(bkpinfo->backup_media_type);
    11461148        mr_asprintf(tmp, "Your backup will probably occupy a single %s. Maybe two.", mds);
    11471149        mr_free(mds);
    1148     } else if (scratchLL > 4) {
    1149         mr_asprintf(tmp, "Your backup will occupy one meeeeellion media! (maybe %s)", number_to_text((int) (scratchLL + 1)));
     1150    } else if (scratchLL > 5) {
     1151        mr_asprintf(tmp, "Your backup will occupy one meeeeellion media! (maybe %s)", tmp1);
    11501152    } else {
    1151         mr_asprintf(tmp, "Your backup will occupy approximately %s media.", number_to_text((int) (scratchLL + 1)));
     1153        mr_asprintf(tmp, "Your backup will occupy approximately %s media.", tmp1);
    11521154    }
    11531155    if (scratchLL < 50) {
    11541156        log_to_screen(tmp);
    11551157    }
     1158    mr_free(tmp1);
    11561159    mr_free(tmp);
    11571160}
  • branches/3.2/mondo/src/common/libmondo-stream.c

    r3610 r3611  
    11771177    /*@ buffers ***************************************************** */
    11781178    char *tempblock;
     1179    char *tmp = NULL;
    11791180
    11801181    /*@ int ********************************************************* */
     
    12081209    }
    12091210    tempblock[i] = '\0';
    1210     log_msg(6, "%s (fname=%s, size=%ld K)",
    1211             marker_to_string(*pcontrol_char), tempblock + 1000,
    1212             (long) (*plen) >> 10);
     1211    tmp = marker_to_string(*pcontrol_char);
     1212    log_msg(6, "%s (fname=%s, size=%ld K)", tmp, tempblock + 1000, (long) (*plen) >> 10);
     1213    mr_free(tmp);
    12131214    paranoid_free(tempblock);
    12141215    return (retval);
     
    17511752    char tempblock[TAPE_BLOCK_SIZE];
    17521753    char *p;
     1754    char *tmp = NULL;
    17531755
    17541756    /*@ int ******************************************************** */
     
    17821784    strcpy(tempblock + 1000, filename);
    17831785    g_tape_posK += fwrite(tempblock, 1, (size_t) TAPE_BLOCK_SIZE, g_tape_stream) / 1024;
    1784     log_msg(6, "%s (fname=%s, size=%ld K)", marker_to_string(control_char), p, (long) length_of_incoming_file >> 10);
     1786    tmp = marker_to_string(control_char);
     1787    log_msg(6, "%s (fname=%s, size=%ld K)", tmp, p, (long) length_of_incoming_file >> 10);
     1788    mr_free(tmp);
    17851789    return (0);
    17861790}
     
    18021806void wrong_marker(int should_be, int it_is)
    18031807{
    1804     log_to_screen("Wrong marker! (Should be %s, is actually %s)", marker_to_string(should_be), marker_to_string(it_is));
     1808    char *tmp1 = NULL;
     1809    char *tmp2 = NULL;
     1810    tmp1 =  marker_to_string(should_be);
     1811    tmp2 =  marker_to_string(it_is);
     1812    log_to_screen("Wrong marker! (Should be %s, is actually %s)", tmp1, tmp2);
     1813    mr_free(tmp1);
     1814    mr_free(tmp2);
    18051815}
    18061816
  • branches/3.2/mondo/src/common/libmondo-string.c

    r3413 r3611  
    147147
    148148/**
    149  * Add commas every third place in @p input.
    150  * @param input The string to commarize.
    151  * @return The string with commas.
    152  * @note The returned string points to static storage that will be overwritten with each call.
    153  */
    154 char *commarize(char *input)
    155 {
    156     char pos_w_commas[MAX_STR_LEN];
    157     static char output[MAX_STR_LEN];
    158     char tmp[MAX_STR_LEN];
    159     int j;
    160 
    161     assert(input != NULL);
    162 
    163     strcpy(tmp, input);
    164     if (strlen(tmp) > 6) {
    165         strcpy(pos_w_commas, tmp);
    166         j = (int) strlen(pos_w_commas);
    167         tmp[j - 6] = ',';
    168         strcpy(tmp + j - 5, pos_w_commas + j - 6);
    169         strcpy(pos_w_commas, tmp);
    170     }
    171     if (strlen(tmp) > 3) {
    172         j = (int) strlen(tmp);
    173         strcpy(pos_w_commas, tmp);
    174         pos_w_commas[j - 3] = ',';
    175         strcpy(pos_w_commas + j - 2, tmp + j - 3);
    176     } else {
    177         strcpy(pos_w_commas, tmp);
    178     }
    179     strcpy(output, pos_w_commas);
    180     return (output);
    181 }
    182 
    183 
    184 /**
    185149 * Turn an entry from the RAID editor's disklist into a GUI-friendly string.
    186150 * The format is: the device left-aligned and padded to 24 places, followed by a space and the
     
    190154 * @param lino The line number from @p disklist to convert to a string.
    191155 * @return The string form of the disklist entry.
    192  * @note The returned string points to static storage and will be overwritten with each call.
     156 * @note The returned string points to storage that needs to be freed by
     157 * caller
    193158 */
    194159char *disklist_entry_to_string(struct list_of_disks *disklist, int lino)
     
    196161
    197162    /*@ buffers ********************************************************** */
    198     static char output[MAX_STR_LEN];
     163    char *output = NULL;
    199164
    200165    assert(disklist != NULL);
    201166
    202     sprintf(output, "%-24s %8d", disklist->el[lino].device,
    203             disklist->el[lino].index);
    204     return (output);
     167    mr_asprintf(output, "%-24s %8d", disklist->el[lino].device, disklist->el[lino].index);
     168    return(output);
    205169}
    206170
     
    301265 * @param marker The marker byte to stringify.
    302266 * @return @p marker as a string.
    303  * @note The returned string points to static storage that will be overwritten with each call.
     267 * @note The returned string points to storage that needs to be freed by
     268 * caller
    304269 */
    305270char *marker_to_string(int marker)
    306271{
    307272    /*@ buffer ****************************************************** */
    308     static char outstr[MAX_STR_LEN];
     273    char *outstr = NULL;
    309274
    310275
     
    313278    switch (marker) {
    314279    case BLK_START_OF_BACKUP:
    315         strcpy(outstr, "BLK_START_OF_BACKUP");
     280        mr_asprintf(outstr, "BLK_START_OF_BACKUP");
    316281        break;
    317282    case BLK_START_OF_TAPE:
    318         strcpy(outstr, "BLK_START_OF_TAPE");
     283        mr_asprintf(outstr, "BLK_START_OF_TAPE");
    319284        break;
    320285    case BLK_START_AN_AFIO_OR_SLICE:
    321         strcpy(outstr, "BLK_START_AN_AFIO_OR_SLICE");
     286        mr_asprintf(outstr, "BLK_START_AN_AFIO_OR_SLICE");
    322287        break;
    323288    case BLK_STOP_AN_AFIO_OR_SLICE:
    324         strcpy(outstr, "BLK_STOP_AN_AFIO_OR_SLICE");
     289        mr_asprintf(outstr, "BLK_STOP_AN_AFIO_OR_SLICE");
    325290        break;
    326291    case BLK_START_AFIOBALLS:
    327         strcpy(outstr, "BLK_START_AFIOBALLS");
     292        mr_asprintf(outstr, "BLK_START_AFIOBALLS");
    328293        break;
    329294    case BLK_STOP_AFIOBALLS:
    330         strcpy(outstr, "BLK_STOP_AFIOBALLS");
     295        mr_asprintf(outstr, "BLK_STOP_AFIOBALLS");
    331296        break;
    332297    case BLK_STOP_BIGGIEFILES:
    333         strcpy(outstr, "BLK_STOP_BIGGIEFILES");
     298        mr_asprintf(outstr, "BLK_STOP_BIGGIEFILES");
    334299        break;
    335300    case BLK_START_A_NORMBIGGIE:
    336         strcpy(outstr, "BLK_START_A_NORMBIGGIE");
     301        mr_asprintf(outstr, "BLK_START_A_NORMBIGGIE");
    337302        break;
    338303    case BLK_START_A_PIHBIGGIE:
    339         strcpy(outstr, "BLK_START_A_PIHBIGGIE");
     304        mr_asprintf(outstr, "BLK_START_A_PIHBIGGIE");
    340305        break;
    341306    case BLK_START_EXTENDED_ATTRIBUTES:
    342         strcpy(outstr, "BLK_START_EXTENDED_ATTRIBUTES");
     307        mr_asprintf(outstr, "BLK_START_EXTENDED_ATTRIBUTES");
    343308        break;
    344309    case BLK_STOP_EXTENDED_ATTRIBUTES:
    345         strcpy(outstr, "BLK_STOP_EXTENDED_ATTRIBUTES");
     310        mr_asprintf(outstr, "BLK_STOP_EXTENDED_ATTRIBUTES");
    346311        break;
    347312    case BLK_START_EXAT_FILE:
    348         strcpy(outstr, "BLK_START_EXAT_FILE");
     313        mr_asprintf(outstr, "BLK_START_EXAT_FILE");
    349314        break;
    350315    case BLK_STOP_EXAT_FILE:
    351         strcpy(outstr, "BLK_STOP_EXAT_FILE");
     316        mr_asprintf(outstr, "BLK_STOP_EXAT_FILE");
    352317        break;
    353318    case BLK_START_BIGGIEFILES:
    354         strcpy(outstr, "BLK_START_BIGGIEFILES");
     319        mr_asprintf(outstr, "BLK_START_BIGGIEFILES");
    355320        break;
    356321    case BLK_STOP_A_BIGGIE:
    357         strcpy(outstr, "BLK_STOP_A_BIGGIE");
     322        mr_asprintf(outstr, "BLK_STOP_A_BIGGIE");
    358323        break;
    359324    case BLK_END_OF_TAPE:
    360         strcpy(outstr, "BLK_END_OF_TAPE");
     325        mr_asprintf(outstr, "BLK_END_OF_TAPE");
    361326        break;
    362327    case BLK_END_OF_BACKUP:
    363         strcpy(outstr, "BLK_END_OF_BACKUP");
     328        mr_asprintf(outstr, "BLK_END_OF_BACKUP");
    364329        break;
    365330    case BLK_ABORTED_BACKUP:
    366         strcpy(outstr, "BLK_ABORTED_BACKUP");
     331        mr_asprintf(outstr, "BLK_ABORTED_BACKUP");
    367332        break;
    368333    case BLK_START_FILE:
    369         strcpy(outstr, "BLK_START_FILE");
     334        mr_asprintf(outstr, "BLK_START_FILE");
    370335        break;
    371336    case BLK_STOP_FILE:
    372         strcpy(outstr, "BLK_STOP_FILE");
     337        mr_asprintf(outstr, "BLK_STOP_FILE");
    373338        break;
    374339    default:
    375         sprintf(outstr, "BLK_UNKNOWN (%d)", marker);
     340        mr_asprintf(outstr, "BLK_UNKNOWN (%d)", marker);
    376341        break;
    377342    }
    378343    return (outstr);
    379344}
    380 
    381 
    382345
    383346
     
    391354 * @param lino The line number in @p mountlist to stringify.
    392355 * @return The string form of <tt>mountlist</tt>-\>el[<tt>lino</tt>].
    393  * @note The returned string points to static storage and will be overwritten with each call.
    394  */
    395 char *mountlist_entry_to_string(struct mountlist_itself *mountlist,
    396                                 int lino)
    397 {
     356 * @note The returned string points to storage that needs to be freed by
     357 * caller
     358 */
     359char *mountlist_entry_to_string(struct mountlist_itself *mountlist, int lino) {
    398360
    399361    /*@ buffer *********************************************************** */
    400     static char output[MAX_STR_LEN];
     362    char *output = NULL;
    401363
    402364    assert(mountlist != NULL);
    403365
    404     sprintf(output, "%-24s %-24s %-10s %8lld", mountlist->el[lino].device,
    405             mountlist->el[lino].mountpoint, mountlist->el[lino].format,
    406             mountlist->el[lino].size / 1024L);
    407     return (output);
     366    mr_asprintf(output, "%-24s %-24s %-10s %8lld", mountlist->el[lino].device, mountlist->el[lino].mountpoint, mountlist->el[lino].format, mountlist->el[lino].size / 1024L);
     367    return(output);
    408368}
    409369
     
    453413 * @param i The number to stringify.
    454414 * @return The string form of @p i.
    455  * @note The returned value points to static strorage that will be overwritten with each call.
     415 * @note The returned value points to strorage that needs to be freed by
     416 * caller
    456417 */
    457418char *number_to_text(int i)
     
    459420
    460421    /*@ buffers ***************************************************** */
    461     static char output[MAX_STR_LEN];
     422    char *output = NULL;
    462423
    463424
     
    466427    switch (i) {
    467428    case 0:
    468         strcpy(output, "zero");
     429        mr_asprintf(output, "zero");
    469430        break;
    470431    case 1:
    471         strcpy(output, "one");
     432        mr_asprintf(output, "one");
    472433        break;
    473434    case 2:
    474         strcpy(output, "two");
     435        mr_asprintf(output, "two");
    475436        break;
    476437    case 3:
    477         strcpy(output, "three");
     438        mr_asprintf(output, "three");
    478439        break;
    479440    case 4:
    480         strcpy(output, "four");
     441        mr_asprintf(output, "four");
    481442        break;
    482443    case 5:
    483         strcpy(output, "five");
     444        mr_asprintf(output, "five");
    484445        break;
    485446    case 6:
    486         strcpy(output, "six");
     447        mr_asprintf(output, "six");
    487448        break;
    488449    case 7:
    489         strcpy(output, "seven");
     450        mr_asprintf(output, "seven");
    490451        break;
    491452    case 8:
    492         strcpy(output, "eight");
     453        mr_asprintf(output, "eight");
    493454        break;
    494455    case 9:
    495         strcpy(output, "nine");
     456        mr_asprintf(output, "nine");
    496457    case 10:
    497         strcpy(output, "ten");
     458        mr_asprintf(output, "ten");
    498459    default:
    499         sprintf(output, "%d", i);
     460        mr_asprintf(output, "%d", i);
    500461    }
    501462    return (output);
     
    875836 * @param raid_level The RAID level to stringify.
    876837 * @return The string form of @p raid_level.
    877  * @note The returned value points to static storage that will be overwritten with each call.
     838 * @note The returned value points to storage that needs to be freed by caller
    878839 */
    879840char *turn_raid_level_number_to_string(int raid_level)
     
    881842
    882843    /*@ buffer ********************************************************** */
    883     static char output[MAX_STR_LEN];
     844    char *output = NULL;
    884845
    885846
    886847
    887848    if (raid_level >= 0) {
    888         sprintf(output, " RAID %-2d ", raid_level);
     849        mr_asprintf(output, " RAID %-2d ", raid_level);
    889850    } else {
    890         sprintf(output, "Linear RAID");
    891     }
    892     return (output);
     851        mr_asprintf(output, "Linear RAID");
     852    }
     853    return(output);
    893854}
    894855
     
    10681029    char *pos_w_commas = NULL;
    10691030    char *mds = NULL;
    1070     char *tmp = NULL;
    10711031
    10721032    assert(bkpinfo != NULL);
    10731033
    10741034    if (bkpinfo->media_size <= 0) {
    1075         mr_asprintf(tmp, "%lld", g_tape_posK);
    1076         mr_asprintf(pos_w_commas, "%s", commarize(tmp));
    1077         mr_free(tmp);
     1035        mr_asprintf(pos_w_commas, "%lld", g_tape_posK);
    10781036        mr_asprintf(outstr, "Volume %d: %s kilobytes archived so far", g_current_media_number, pos_w_commas);
    10791037        mr_free(pos_w_commas);
  • branches/3.2/mondo/src/mondorestore/mondo-prep.c

    r3610 r3611  
    18391839    mr_asprintf(partcode, "");
    18401840} else if (strlen(format) >= 1 && strlen(format) <= 2) {
    1841     mr_asprintf(partcode, format);
     1841    mr_asprintf(partcode, "%s", format);
    18421842} else {
    18431843    /* probably an image */
     
    18471847
    18481848#ifdef __FreeBSD__
    1849     mr_asprintf(partcode, format);  // was a5
     1849    mr_asprintf(partcode, "%s", format);    // was a5
    18501850#else
    1851     mr_asprintf(partcode, format);  // was 83
     1851    mr_asprintf(partcode, "%s", format);    // was 83
    18521852#endif
    18531853}
  • branches/3.2/mondo/src/mondorestore/mondo-rstr-mountlist.c

    r3564 r3611  
    5555    /*@ buffers ******************************************************** */
    5656    char tmp = NULL;
     57    char tmp1 = NULL;
    5758    char device[MAX_STR_LEN];
    5859
     
    112113            }
    113114            if (device_copies > 1) {
    114                 mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies), device);
     115                tmp1 = number_to_text(device_copies);
     116                mr_asprintf(tmp, " %s %s's.", tmp1, device);
     117                mr_free(tmp1);
    115118                if (!strstr(flaws_str, tmp)) {
    116119                    log_it(tmp);
     
    209212            }
    210213            if (device_copies > 1) {
    211                 mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies), device);
     214                tmp1 = number_to_text(device_copies);
     215                mr_asprintf(tmp, " %s %s's.", tmp1, device);
     216                mr_free(tmp1);
    212217                if (!strstr(flaws_str, "%s", tmp)) {
    213218                    log_it(tmp);
     
    271276                }
    272277                if (device_copies > 1) {
    273                     mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies), device);
     278                    tmp1 = number_to_text(device_copies);
     279                    mr_asprintf(tmp, " %s %s's.", tmp1, device);
     280                    mr_free(tmp1);
    274281                    if (!strstr(flaws_str, tmp)) {
    275282                        log_it(tmp);
     
    374381    /*@ buffers ******************************************************** */
    375382    char *tmp = NULL;
     383    char *tmp1 = NULL;
    376384    char *device = NULL;
    377385    char *flaws_str = NULL;
     
    452460        }
    453461        if (device_copies > 1) {
    454             mr_asprintf(tmp, " %s %s's.", number_to_text(device_copies), device);
     462            tmp1 = number_to_text(device_copies);
     463            mr_asprintf(tmp, " %s %s's.", tmp1, device);
     464            mr_free(tmp1);
    455465            if (!strstr(flaws_str, tmp)) {
    456466                log_it(tmp);
     
    536546    struct list_of_disks *drivelist;
    537547    char *tmp = NULL;
     548    char *tmp1 = NULL;
    538549    char *flaws_str = NULL;
    539550
     
    589600        }
    590601        if (copies > 1 && last_copy == currline && strcmp(curr_mountpoint, "raid")) {
    591             mr_asprintf(tmp, " %s %s's.", number_to_text(copies), curr_mountpoint);
     602            tmp1 = number_to_text(copies);
     603            mr_asprintf(tmp, " %s %s's.", tmp1, curr_mountpoint);
     604            mr_free(tmp1);
    592605            log_msg(8,"Adding: %s to flaws_str", tmp);
    593606            if (flaws_str != NULL) {
  • branches/3.2/mondo/src/mondorestore/mondo-rstr-newt.c

    r3289 r3611  
    12961296    }
    12971297    mr_free(size_str);
    1298     newtListboxSetEntry(listbox, (long) keylist[currline],
    1299                         mountlist_entry_to_string(mountlist, currline));
     1298
     1299    tmp = mountlist_entry_to_string(mountlist, currline);
     1300    newtListboxSetEntry(listbox, (long) keylist[currline], tmp);
     1301    mr_free(tmp);
     1302
    13001303    /* if new /dev/md RAID device then do funky stuff */
    13011304    if (strstr(mountlist->el[currline].device, RAID_DEVICE_STUB)
     
    15801583        mr_free(title_of_editraidForm_window);
    15811584        mr_asprintf(title_of_editraidForm_window, "Edit %s", raidrec->raid_device);
    1582         mr_asprintf(sz_raid_level, "%s", turn_raid_level_number_to_string(raidrec->raid_level));
     1585        sz_raid_level = turn_raid_level_number_to_string(raidrec->raid_level);
    15831586        sz_data_disks = number_of_disks_as_string(raidrec->data_disks.entries, "data");
    15841587        sz_spare_disks = number_of_disks_as_string(raidrec->spare_disks.entries, "spare");
     
    23352338    /** long **************************************************************/
    23362339    long i = 0;
     2340    char *tmp = NULL;
    23372341
    23382342    assert(disklist != NULL);
     
    23462350    }
    23472351    for (i = 0; i < disklist->entries; i++) {
    2348         newtListboxAppendEntry(listbox,
    2349                                disklist_entry_to_string(disklist, i),
    2350                                keylist[i]);
     2352        tmp = disklist_entry_to_string(disklist, i);
     2353        newtListboxAppendEntry(listbox, tmp, keylist[i]);
     2354        mr_free(tmp);
    23512355    }
    23522356}
     
    23672371    /** long **************************************************************/
    23682372    long i = 0;
     2373    char * tmp = NULL;
    23692374
    23702375    assert(mountlist != NULL);
     
    23782383    }
    23792384    for (i = 0; i < mountlist->entries; i++) {
    2380         newtListboxAppendEntry(listbox,
    2381                                mountlist_entry_to_string(mountlist, i),
    2382                                keylist[i]);
     2385        tmp = mountlist_entry_to_string(mountlist, i);
     2386        newtListboxAppendEntry(listbox, tmp, keylist[i]);
     2387        mr_free(tmp);
    23832388    }
    23842389}
Note: See TracChangeset for help on using the changeset viewer.