Changeset 2300


Ignore:
Timestamp:
Jul 23, 2009, 7:40:07 PM (10 years ago)
Author:
bruno
Message:
  • Replace sprintf by mr_asprintf in mondo-rstr-newt.c (end of first modifications round)
Location:
branches/2.2.10
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2.10/mondo/src/mondorestore/mondo-rstr-newt.c

    r2230 r2300  
    5151{
    5252    /** buffers ***********************************************************/
    53     char tmp[MAX_STR_LEN];
     53    char *tmp = NULL;
    5454
    5555    /** newt **************************************************************/
     
    7777    newtPushHelpLine
    7878        ("   Add one of the following unallocated RAID partitions to this RAID device.");
    79     sprintf(tmp, "%-26s %s", "Device", "Size");
     79    mr_asprintf(&tmp, "%-26s %s", "Device", "Size");
    8080    headerMsg = newtLabel(1, 1, tmp);
    8181    partitionsListbox =
     
    111111    }
    112112    newtFormDestroy(myForm);
     113    mr_free(tmp);
    113114    newtPopWindow();
    114115    newtPopHelpLine();
     
    177178#endif
    178179    size_str[0] = '\0';
    179     /* sprintf(size_str,""); */
    180180    newtOpenWindow(20, 5, 48, 10, "Add entry");
    181181    label0 = newtLabel(2, 1, "Device:    ");
     
    316316
    317317    /** buffers ***********************************************************/
    318     char tmp[MAX_STR_LEN];
     318    char tmp = NULL;
    319319
    320320
     
    325325         && strcmp(raidlist->el[i].volname, basename(raid_device)); i++);
    326326    if (i == raidlist->entries) {
    327         sprintf(tmp,
    328                 "Cannot calc size of raid device %s - cannot find it in raidlist",
    329                 raid_device);
     327        mr_asprintf(&tmp, "Cannot calc size of raid device %s - cannot find it in raidlist", raid_device);
    330328        log_it(tmp);
     329        mr_free(tmp);
    331330        return (0);             // Isn't this more sensible than 999999999? If the raid dev !exists,
    332331        // then it has no size, right?
     
    389388    }
    390389
    391     sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device,
    392             (long) smallest_plex);
     390    mr_asprintf(&tmp, "I have calculated %s's real size to be %ld", raid_device, (long) smallest_plex);
    393391    log_it(tmp);
     392    mr_free(tmp);
    394393    return (smallest_plex);
    395394#else
     
    409408
    410409    /** buffers ***********************************************************/
    411     char tmp[MAX_STR_LEN];
     410    char tmp = NULL;
    412411
    413412    assert(mountlist != NULL);
     
    419418         && strcmp(raidlist->el[i].raid_device, raid_device); i++);
    420419    if (i == raidlist->entries) {
    421         sprintf(tmp,
    422                 "Cannot calc size of raid device %s - cannot find it in raidlist",
    423                 raid_device);
     420        mr_asprintf(&tmp, "Cannot calc size of raid device %s - cannot find it in raidlist", raid_device);
    424421        log_it(tmp);
     422        mr_free(tmp);
    425423        return (999999999);
    426424    }
     
    445443        total_size = smallest_partition * (noof_partitions - 1);
    446444    }
    447     sprintf(tmp, "I have calculated %s's real size to be %ld", raid_device,
    448             (long) total_size);
     445    mr_asprintf(&tmp, "I have calculated %s's real size to be %ld", raid_device, (long) total_size);
    449446    log_it(tmp);
     447    mr_free(tmp);
    450448    return (total_size);
    451449#endif
     
    471469    /** buffers ***********************************************************/
    472470    char tmp[MAX_STR_LEN];
    473     char prompt[MAX_STR_LEN];
    474     char sz[MAX_STR_LEN];
    475 
    476     sprintf(prompt,
    477             "Please enter the RAID level you want. (concat, striped, raid5)");
     471    char *prompt = NULL;
     472    char *sz = NULL;
     473
     474    mr_asprintf(&prompt, "Please enter the RAID level you want. (concat, striped, raid5)");
    478475    if (raidrec->raidlevel == -1) {
    479476        strcpy(tmp, "concat");
     
    486483        res = popup_and_get_string("Specify RAID level", prompt, tmp, 10);
    487484        if (!res) {
     485            mr_free(prompt);
    488486            return;
    489487        }
    490488        strip_spaces(tmp);
    491489        if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') {
    492             strcpy(sz, tmp);
     490            mr_asprintf(&sz, "%s", tmp);
    493491            strncpy(tmp, sz + 1, strlen(sz) - 2);
    494492            tmp[strlen(sz) - 2] = '\0';
     493            mr_free(sz);
    495494        }
    496495        if (!strcmp(tmp, "concat")) {
     
    513512        }
    514513    }
     514    mr_free(prompt);
    515515    raidrec->raidlevel = out;
    516516#else
    517517    /** buffers ***********************************************************/
    518518    char tmp[MAX_STR_LEN];
    519     char personalities[MAX_STR_LEN];
    520     char prompt[MAX_STR_LEN];
    521     char sz[MAX_STR_LEN];
     519    char *personalities = NULL;
     520    char *prompt = NULL;
     521    char *sz = NULL;
    522522    int out = 0, res = 0;
    523523
     
    526526    system
    527527        ("grep Pers /proc/mdstat > /tmp/raid-personalities.txt 2> /dev/null");
    528     strcpy(personalities,
    529            last_line_of_file("/tmp/raid-personalities.txt"));
    530     sprintf(prompt, "Please enter the RAID level you want. %s",
    531             personalities);
     528    mr_asprintf(&personalities, "%s", last_line_of_file("/tmp/raid-personalities.txt"));
     529    mr_asprintf(&prompt, "Please enter the RAID level you want. %s", personalities);
     530    mr_free(personalities);
     531
    532532    if (raidrec->raid_level == -1) {
    533533        strcpy(tmp, "linear");
     
    540540        res = popup_and_get_string("Specify RAID level", prompt, tmp, 10);
    541541        if (!res) {
     542            mr_free(prompt);
    542543            return;
    543544        }
    544545        strip_spaces(tmp);
    545546        if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') {
    546             strcpy(sz, tmp);
     547            mr_asprintf(&sz, "%s", tmp);
    547548            strncpy(tmp, sz + 1, strlen(sz) - 2);
    548549            tmp[strlen(sz) - 2] = '\0';
     550            mr_free(sz);
    549551        }
    550552        if (!strcmp(tmp, "linear")) {
     
    567569        }
    568570    }
     571    mr_free(prompt);
    569572    raidrec->raid_level = out;
    570573#endif
     
    592595
    593596    /** buffers ***********************************************************/
    594     char tmp[MAX_STR_LEN];
     597    char *tmp = NULL;
    595598
    596599    assert(mountlist != NULL);
     
    604607             pos++);
    605608        if (pos < mountlist->entries) {
    606             sprintf(tmp,
    607                     "Deleting partition %s cos it was part of a now-defunct RAID",
    608                     mountlist->el[pos].device);
     609            mr_asprintf(&tmp, "Deleting partition %s cos it was part of a now-defunct RAID", mountlist->el[pos].device);
    609610            log_it(tmp);
     611            mr_free(tmp);
     612
    610613            memcpy((void *) &mountlist->el[pos],
    611614                   (void *) &mountlist->el[mountlist->entries - 1],
     
    633636    /** int ***************************************************************/
    634637    int pos = 0;
     638    int res = 0;
    635639
    636640    /** buffers ***********************************************************/
    637     char tmp[MAX_STR_LEN];
     641    char *tmp = NULL;
    638642
    639643    assert(disklist != NULL);
    640644    assert_string_is_neither_NULL_nor_zerolength(raid_device);
    641645
    642     sprintf(tmp, "Delete %s from RAID device %s - are you sure?",
    643             disklist->el[currline].device, raid_device);
    644     if (!ask_me_yes_or_no(tmp)) {
     646    mr_asprintf(&tmp, "Delete %s from RAID device %s - are you sure?", disklist->el[currline].device, raid_device);
     647    res = ask_me_yes_or_no(tmp);
     648    mr_free(tmp);
     649
     650    if (!res) {
    645651        return;
    646652    }
    647653    for (pos = currline; pos < disklist->entries - 1; pos++) {
    648         /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */
    649654        strcpy(disklist->el[pos].device, disklist->el[pos + 1].device);
    650655    }
     
    672677    /** int ***************************************************************/
    673678    int pos = 0;
     679    int res = 0;
    674680
    675681    /** buffers ***********************************************************/
    676     char tmp[MAX_STR_LEN];
     682    char *tmp = NULL;
    677683    char device[MAX_STR_LEN];
    678684
     
    683689    assert(keylist != NULL);
    684690
     691    /* BERLIOS: Why isn't device initialized here ? what is expected */
    685692    pos =
    686693        which_raid_device_is_using_this_partition(raidlist,
     
    688695                                                  device);
    689696    if (pos >= 0) {
    690         sprintf(tmp, "Cannot delete %s: it is in use by RAID device %s",
    691                 mountlist->el[currline].device,
    692                 raidlist->el[pos].OSSWAP(raid_device, volname));
     697        mr_asprintf(&tmp, "Cannot delete %s: it is in use by RAID device %s", mountlist->el[currline].device, raidlist->el[pos].OSSWAP(raid_device, volname));
    693698        popup_and_OK(tmp);
     699        mr_free(tmp);
    694700        return;
    695701    }
    696     sprintf(tmp, "Delete %s - are you sure?",
    697             mountlist->el[currline].device);
    698     if (!ask_me_yes_or_no(tmp)) {
     702    mr_asprintf(&tmp, "Delete %s - are you sure?", mountlist->el[currline].device);
     703    res = ask_me_yes_or_no(tmp);
     704    mr_free(tmp);
     705
     706    if (!res) {
    699707        return;
    700708    }
     
    739747
    740748    /** buffers ***********************************************************/
    741     char tmp[MAX_STR_LEN];
     749    char *tmp = NULL;
    742750
    743751    assert(mountlist != NULL);
     
    749757        return;
    750758    }
    751     sprintf(tmp, "Do you want me to delete %s's partitions, too?", device);
     759    mr_asprintf(&tmp, "Do you want me to delete %s's partitions, too?", device);
    752760    delete_partitions_too = ask_me_yes_or_no(tmp);
    753761    if (delete_partitions_too) {
     
    793801        items--;
    794802    }
     803    mr_free(tmp);
    795804    raidlist->entries = items;
    796805}
     
    808817
    809818    /** buffers ************************************************************/
    810     char tmp[MAX_STR_LEN];
     819    char *tmp = NULL;
     820    int res = 0;
    811821
    812822    /** structures *********************************************************/
     
    816826
    817827    av = &raidrec->additional_vars;
    818     sprintf(tmp, "Delete %s - are you sure?", av->el[lino].label);
    819     if (ask_me_yes_or_no(tmp)) {
     828    mr_asprintf(&tmp, "Delete %s - are you sure?", av->el[lino].label);
     829    res = ask_me_yes_or_no(tmp);
     830    mr_free(tmp);
     831
     832    if (res) {
    820833        if (!strcmp(av->el[lino].label, "persistent-superblock")
    821834            || !strcmp(av->el[lino].label, "chunk-size")) {
    822             sprintf(tmp, "%s must not be deleted. It would be bad.",
    823                     av->el[lino].label);
     835            mr_asprintf(&tmp, "%s must not be deleted. It would be bad.", av->el[lino].label);
    824836            popup_and_OK(tmp);
     837            mr_free(tmp);
    825838        } else {
    826839            memcpy((void *) &av->el[lino], (void *) &av->el[av->entries--],
     
    858871    static char current_filename[MAX_STR_LEN];
    859872    char tmp[MAX_STR_LEN + 2];
     873    char *tmp1 = NULL;
    860874
    861875    /** bool *************************************************************/
     
    888902                if (!warned_already) {
    889903                    warned_already = TRUE;
    890                     sprintf(tmp,
    891                             "Too many lines. Displaying first %d entries only. Close a directory to see more.",
    892                             ARBITRARY_MAXIMUM);
    893                     popup_and_OK(tmp);
     904                    mr_asprintf(&tmp1, "Too many lines. Displaying first %d entries only. Close a directory to see more.", ARBITRARY_MAXIMUM);
     905                    popup_and_OK(tmp1);
     906                    mr_free(tmp1);
    894907                }
    895908            } else {
     
    910923                (g_strings_of_flist_window[i],
    911924                 g_strings_of_flist_window[i - 1]) < 0) {
    912                 strcpy(tmp, g_strings_of_flist_window[i]);
     925                mr_asprintf(&tmp1, g_strings_of_flist_window[i]);
    913926                strcpy(g_strings_of_flist_window[i],
    914927                       g_strings_of_flist_window[i - 1]);
    915                 strcpy(g_strings_of_flist_window[i - 1], tmp);
     928                strcpy(g_strings_of_flist_window[i - 1], tmp1);
     929                mr_free(tmp1);
    916930                dummybool = g_is_path_selected[i];
    917931                g_is_path_selected[i] = g_is_path_selected[i - 1];
     
    10181032
    10191033    /** buffers ***********************************************************/
    1020     char tmp[MAX_STR_LEN];
     1034    char *tmp = NULL;
    10211035
    10221036    /** bool **************************************************************/
     
    10661080                indexno = 0;
    10671081            }
    1068             sprintf(tmp, "You selected '%s'",
    1069                     g_strings_of_flist_window[indexno]);
     1082            mr_asprintf(&tmp, "You selected '%s'", g_strings_of_flist_window[indexno]);
    10701083            log_it(tmp);
     1084            mr_free(tmp);
     1085
    10711086            if (b_res == bMore) {
    10721087                g_is_path_expanded[indexno] = TRUE;
     
    11641179    char size_str[MAX_STR_LEN];
    11651180    char format_str[MAX_STR_LEN];
    1166     char tmp[MAX_STR_LEN];
     1181    char *tmp = NULL;
    11671182    char device_used_to_be[MAX_STR_LEN];
    11681183    char mountpt_used_to_be[MAX_STR_LEN];
     
    12631278                                                 device);
    12641279                if (j < 0) {
    1265                     sprintf(tmp,
    1266                             "/etc/raidtab does not have an entry for %s; please delete it and add it again",
    1267                             mountlist->el[currline].device);
     1280                    mr_asprintf(&tmp, "/etc/raidtab does not have an entry for %s; please delete it and add it again", mountlist->el[currline].device);
    12681281                    popup_and_OK(tmp);
     1282                    mr_free(tmp);
    12691283                } else {
    12701284                    log_it("edit_raidlist_entry - calling");
     
    13501364    }
    13511365    if (!found) {
    1352         sprintf(raidlist->disks.el[raidlist->disks.entries].name,
    1353                 "drive%i", raidlist->disks.entries);
    1354         sprintf(raidrec->sd[raidrec->subdisks].which_device, "drive%i",
    1355                 raidlist->disks.entries);
     1366        sprintf(raidlist->disks.el[raidlist->disks.entries].name, "drive%i", raidlist->disks.entries);
     1367        sprintf(raidrec->sd[raidrec->subdisks].which_device, "drive%i", raidlist->disks.entries);
    13561368        strcpy(raidlist->disks.el[raidlist->disks.entries++].device, temp);
    13571369    }
     
    14261438    void *keylist[10];
    14271439    void *curr_choice;
     1440    char *raidlevel = NULL;
     1441    char *chunksize = NULL;
     1442    char *msg = NULL;
    14281443
    14291444    int currline2 = 0;
     1445    int res = 0;
    14301446
    14311447    log_it("Started edit_raidlist_entry");
     
    14571473            keylist[i] = (void *) i;
    14581474            if (i < raidrec->plexes) {
    1459                 char pname[64], entry[MAX_STR_LEN], raidlevel[64],
    1460                     chunksize[64];
     1475                char pname[64], entry[MAX_STR_LEN];
    14611476                switch (raidrec->plex[i].raidlevel) {
    14621477                case -1:
    1463                     strcpy(raidlevel, "concat");
     1478                    mr_asprintf(&raidlevel, "concat");
    14641479                    break;
    14651480                case 0:
    1466                     strcpy(raidlevel, "striped");
     1481                    mr_asprintf(&raidlevel, "striped");
    14671482                    break;
    14681483                case 5:
    1469                     strcpy(raidlevel, "raid5");
     1484                    mr_asprintf(&raidlevel, "raid5");
    14701485                    break;
    14711486                default:
    1472                     sprintf(raidlevel, "raid%i",
    1473                             raidrec->plex[i].raidlevel);
     1487                    mr_asprintf(&raidlevel, "raid%i", raidrec->plex[i].raidlevel);
    14741488                    break;
    14751489                }
    14761490
    14771491                if (raidrec->plex[i].raidlevel == -1) {
    1478                     strcpy(chunksize, "N/A");
     1492                    mr_asprintf(&chunksize, "N/A");
    14791493                } else {
    1480                     sprintf(chunksize, "%dk", raidrec->plex[i].stripesize);
     1494                    mr_asprintf(&chunksize, "%dk", raidrec->plex[i].stripesize);
    14811495                }
    14821496                snprintf(pname, 64, "%s.p%i", raidrec->volname, i);
     
    14841498                         pname, raidlevel, chunksize,
    14851499                         raidrec->plex[i].subdisks);
     1500                mr_free(raidlevel);
     1501                mr_free(chunksize);
     1502
    14861503                newtListboxAppendEntry(plexesListbox, entry, keylist[i]);
    14871504            }
     
    15051522
    15061523        if (b_res == bDelete) {
    1507             char msg[MAX_STR_LEN];
    1508             sprintf(msg, "Are you sure you want to delete %s.p%i?",
    1509                     raidrec->volname, currline2);
    1510             if (ask_me_yes_or_no(msg)) {
     1524            mr_asprintf(&msg, "Are you sure you want to delete %s.p%i?", raidrec->volname, currline2);
     1525            res = ask_me_yes_or_no(msg);
     1526            mr_free(msg);
     1527
     1528            if (res) {
    15111529                log_it("Deleting RAID plex");
    15121530                memcpy((void *) &raidrec->plex[currline2],
     
    18501868            }
    18511869        }
    1852 #if 0
    1853     } else {
    1854         edit_raid_subdisk(raidlist, raidrec, &raidrec->sd[currline3],
    1855                           currline3);
    1856     }
    1857 #endif
    18581870    newtFormDestroy(editraidForm);
    18591871    newtRefresh();
     
    18941906    }
    18951907}
    1896 
    1897 
    1898 /* I'm not racist against white people. I just don't like people who think Liberia is near Spain.       - Hugo, 09/01/2001 */
    18991908
    19001909#endif
     
    19371946
    19381947    /** buffers **********************************************************/
    1939     char tmp[MAX_STR_LEN];
     1948    char *tmp = NULL;
    19401949    char *flaws_str_A = NULL;
    19411950    char *flaws_str_B = NULL;
     
    19611970    bCancel = newtCompactButton(i += 12, 17, "Cancel");
    19621971    bOK = newtCompactButton(i += 12, 17, "  OK  ");
    1963     sprintf(tmp, "%-24s %-24s %-8s  %s", "Device", "Mountpoint", "Format",
    1964             "Size (MB)");
     1972    mr_asprintf(&tmp, "%-24s %-24s %-8s  %s", "Device", "Mountpoint", "Format", "Size (MB)");
    19651973    headerMsg = newtLabel(2, 1, tmp);
    19661974    flawsLabelA = newtLabel(2, 13, flaws_str_A);
     
    19972005        } else if (b_res == bReload) {
    19982006            if (ask_me_yes_or_no("Reload original mountlist?")) {
    1999 /*
    2000 This would be really dumb. RAIDTAB_FNAME is #define'd.   --- Hugo, 2003/04/24
    2001           if (!RAIDTAB_FNAME[0])
    2002         {
    2003                   strcpy(RAIDTAB_FNAME, "/etc/raidtab");
    2004           log_it("Warning - raidtab_fname is blank. Assuming %s", g_raidtab_fname);
    2005         }
    2006 */
    20072007                load_mountlist(mountlist, mountlist_fname);
    20082008                load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME);
     
    20382038        }
    20392039    }
    2040     paranoid_free(flaws_str_A);
    2041     paranoid_free(flaws_str_B);
    2042     paranoid_free(flaws_str_C);
    20432040    newtFormDestroy(myForm);
     2041
     2042    mr_free(flaws_str_A);
     2043    mr_free(flaws_str_B);
     2044    mr_free(flaws_str_C);
     2045    mr_free(tmp);
     2046
    20442047    newtPopWindow();
    20452048    newtPopHelpLine();
     
    22212224    int i = 0;
    22222225#ifdef __FreeBSD__
    2223     char vdev[64];
     2226    char *vdev = NULL;
     2227    int res = 0;
    22242228#else
    22252229// Linux
     
    22312235#ifdef __FreeBSD__
    22322236    for (i = 0; i < raidlist->entries; i++) {
    2233         sprintf(vdev, "/dev/vinum/%s", raidlist->el[i].volname);
    2234         if (!strcmp(device, vdev))
     2237        mr_asprintf(&vdev, "/dev/vinum/%s", raidlist->el[i].volname);
     2238        res = strcmp(device, vdev);
     2239        mr_free(vdev);
     2240
     2241        if (!res)
    22352242            break;
    22362243    }
     
    25952602{
    25962603    /** buffers ********************************************************/
    2597     char tmp[MAX_STR_LEN];
     2604    char *tmp = NULL;
    25982605
    25992606    /** int ************************************************************/
     
    26072614    pos = which_raid_device_is_using_this_partition(raidlist, old_dev);
    26082615    if (pos < 0) {
    2609         sprintf(tmp, "No need to rejig %s in raidlist: it's not listed.",
    2610                 old_dev);
     2616        mr_asprintf(&tmp, "No need to rejig %s in raidlist: it's not listed.", old_dev);
    26112617        log_it(tmp);
     2618        mr_free(tmp);
    26122619    } else {
    26132620        if ((j =
     
    26412648#endif
    26422649        else {
    2643             sprintf(tmp,
    2644                     "%s is supposed to be listed in this raid dev but it's not...",
    2645                     old_dev);
     2650            mr_asprintf(&tmp, "%s is supposed to be listed in this raid dev but it's not...", old_dev);
    26462651            log_it(tmp);
     2652            mr_free(tmp);
    26472653        }
    26482654    }
  • branches/2.2.10/tools/quality

    r2296 r2300  
    2828
    2929# How many sprintf/strcat/strcpy vs asprintf are they
    30 for s in asprintf mr_asprintf sprintf snprintf strcat strcpy strncpy fgets malloc mr_malloc malloc_string getline mr_getline MAX_STR_LEN getcwd goto free mr_free paranoid_free paranoid_system; do
     30for s in asprintf mr_asprintf sprintf snprintf strcat strcpy strncpy fgets malloc mr_malloc malloc_string getline mr_getline MAX_STR_LEN getcwd goto free mr_free paranoid_free paranoid_system mr_system assert; do
    3131    echo "monodrescue $s usage : "
    3232    tot=0
Note: See TracChangeset for help on using the changeset viewer.