Changeset 2300 in MondoRescue
- Timestamp:
- Jul 23, 2009, 7:40:07 PM (16 years ago)
- 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 51 51 { 52 52 /** buffers ***********************************************************/ 53 char tmp[MAX_STR_LEN];53 char *tmp = NULL; 54 54 55 55 /** newt **************************************************************/ … … 77 77 newtPushHelpLine 78 78 (" 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"); 80 80 headerMsg = newtLabel(1, 1, tmp); 81 81 partitionsListbox = … … 111 111 } 112 112 newtFormDestroy(myForm); 113 mr_free(tmp); 113 114 newtPopWindow(); 114 115 newtPopHelpLine(); … … 177 178 #endif 178 179 size_str[0] = '\0'; 179 /* sprintf(size_str,""); */180 180 newtOpenWindow(20, 5, 48, 10, "Add entry"); 181 181 label0 = newtLabel(2, 1, "Device: "); … … 316 316 317 317 /** buffers ***********************************************************/ 318 char tmp [MAX_STR_LEN];318 char tmp = NULL; 319 319 320 320 … … 325 325 && strcmp(raidlist->el[i].volname, basename(raid_device)); i++); 326 326 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); 330 328 log_it(tmp); 329 mr_free(tmp); 331 330 return (0); // Isn't this more sensible than 999999999? If the raid dev !exists, 332 331 // then it has no size, right? … … 389 388 } 390 389 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); 393 391 log_it(tmp); 392 mr_free(tmp); 394 393 return (smallest_plex); 395 394 #else … … 409 408 410 409 /** buffers ***********************************************************/ 411 char tmp [MAX_STR_LEN];410 char tmp = NULL; 412 411 413 412 assert(mountlist != NULL); … … 419 418 && strcmp(raidlist->el[i].raid_device, raid_device); i++); 420 419 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); 424 421 log_it(tmp); 422 mr_free(tmp); 425 423 return (999999999); 426 424 } … … 445 443 total_size = smallest_partition * (noof_partitions - 1); 446 444 } 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); 449 446 log_it(tmp); 447 mr_free(tmp); 450 448 return (total_size); 451 449 #endif … … 471 469 /** buffers ***********************************************************/ 472 470 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)"); 478 475 if (raidrec->raidlevel == -1) { 479 476 strcpy(tmp, "concat"); … … 486 483 res = popup_and_get_string("Specify RAID level", prompt, tmp, 10); 487 484 if (!res) { 485 mr_free(prompt); 488 486 return; 489 487 } 490 488 strip_spaces(tmp); 491 489 if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') { 492 strcpy(sz, tmp);490 mr_asprintf(&sz, "%s", tmp); 493 491 strncpy(tmp, sz + 1, strlen(sz) - 2); 494 492 tmp[strlen(sz) - 2] = '\0'; 493 mr_free(sz); 495 494 } 496 495 if (!strcmp(tmp, "concat")) { … … 513 512 } 514 513 } 514 mr_free(prompt); 515 515 raidrec->raidlevel = out; 516 516 #else 517 517 /** buffers ***********************************************************/ 518 518 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; 522 522 int out = 0, res = 0; 523 523 … … 526 526 system 527 527 ("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 532 532 if (raidrec->raid_level == -1) { 533 533 strcpy(tmp, "linear"); … … 540 540 res = popup_and_get_string("Specify RAID level", prompt, tmp, 10); 541 541 if (!res) { 542 mr_free(prompt); 542 543 return; 543 544 } 544 545 strip_spaces(tmp); 545 546 if (tmp[0] == '[' && tmp[strlen(tmp) - 1] == ']') { 546 strcpy(sz, tmp);547 mr_asprintf(&sz, "%s", tmp); 547 548 strncpy(tmp, sz + 1, strlen(sz) - 2); 548 549 tmp[strlen(sz) - 2] = '\0'; 550 mr_free(sz); 549 551 } 550 552 if (!strcmp(tmp, "linear")) { … … 567 569 } 568 570 } 571 mr_free(prompt); 569 572 raidrec->raid_level = out; 570 573 #endif … … 592 595 593 596 /** buffers ***********************************************************/ 594 char tmp[MAX_STR_LEN];597 char *tmp = NULL; 595 598 596 599 assert(mountlist != NULL); … … 604 607 pos++); 605 608 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); 609 610 log_it(tmp); 611 mr_free(tmp); 612 610 613 memcpy((void *) &mountlist->el[pos], 611 614 (void *) &mountlist->el[mountlist->entries - 1], … … 633 636 /** int ***************************************************************/ 634 637 int pos = 0; 638 int res = 0; 635 639 636 640 /** buffers ***********************************************************/ 637 char tmp[MAX_STR_LEN];641 char *tmp = NULL; 638 642 639 643 assert(disklist != NULL); 640 644 assert_string_is_neither_NULL_nor_zerolength(raid_device); 641 645 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) { 645 651 return; 646 652 } 647 653 for (pos = currline; pos < disklist->entries - 1; pos++) { 648 /* memcpy((void*)&disklist->el[pos], (void*)&disklist->el[pos+1], sizeof(struct s_disk)); */649 654 strcpy(disklist->el[pos].device, disklist->el[pos + 1].device); 650 655 } … … 672 677 /** int ***************************************************************/ 673 678 int pos = 0; 679 int res = 0; 674 680 675 681 /** buffers ***********************************************************/ 676 char tmp[MAX_STR_LEN];682 char *tmp = NULL; 677 683 char device[MAX_STR_LEN]; 678 684 … … 683 689 assert(keylist != NULL); 684 690 691 /* BERLIOS: Why isn't device initialized here ? what is expected */ 685 692 pos = 686 693 which_raid_device_is_using_this_partition(raidlist, … … 688 695 device); 689 696 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)); 693 698 popup_and_OK(tmp); 699 mr_free(tmp); 694 700 return; 695 701 } 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) { 699 707 return; 700 708 } … … 739 747 740 748 /** buffers ***********************************************************/ 741 char tmp[MAX_STR_LEN];749 char *tmp = NULL; 742 750 743 751 assert(mountlist != NULL); … … 749 757 return; 750 758 } 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); 752 760 delete_partitions_too = ask_me_yes_or_no(tmp); 753 761 if (delete_partitions_too) { … … 793 801 items--; 794 802 } 803 mr_free(tmp); 795 804 raidlist->entries = items; 796 805 } … … 808 817 809 818 /** buffers ************************************************************/ 810 char tmp[MAX_STR_LEN]; 819 char *tmp = NULL; 820 int res = 0; 811 821 812 822 /** structures *********************************************************/ … … 816 826 817 827 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) { 820 833 if (!strcmp(av->el[lino].label, "persistent-superblock") 821 834 || !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); 824 836 popup_and_OK(tmp); 837 mr_free(tmp); 825 838 } else { 826 839 memcpy((void *) &av->el[lino], (void *) &av->el[av->entries--], … … 858 871 static char current_filename[MAX_STR_LEN]; 859 872 char tmp[MAX_STR_LEN + 2]; 873 char *tmp1 = NULL; 860 874 861 875 /** bool *************************************************************/ … … 888 902 if (!warned_already) { 889 903 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); 894 907 } 895 908 } else { … … 910 923 (g_strings_of_flist_window[i], 911 924 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]); 913 926 strcpy(g_strings_of_flist_window[i], 914 927 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); 916 930 dummybool = g_is_path_selected[i]; 917 931 g_is_path_selected[i] = g_is_path_selected[i - 1]; … … 1018 1032 1019 1033 /** buffers ***********************************************************/ 1020 char tmp[MAX_STR_LEN];1034 char *tmp = NULL; 1021 1035 1022 1036 /** bool **************************************************************/ … … 1066 1080 indexno = 0; 1067 1081 } 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]); 1070 1083 log_it(tmp); 1084 mr_free(tmp); 1085 1071 1086 if (b_res == bMore) { 1072 1087 g_is_path_expanded[indexno] = TRUE; … … 1164 1179 char size_str[MAX_STR_LEN]; 1165 1180 char format_str[MAX_STR_LEN]; 1166 char tmp[MAX_STR_LEN];1181 char *tmp = NULL; 1167 1182 char device_used_to_be[MAX_STR_LEN]; 1168 1183 char mountpt_used_to_be[MAX_STR_LEN]; … … 1263 1278 device); 1264 1279 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); 1268 1281 popup_and_OK(tmp); 1282 mr_free(tmp); 1269 1283 } else { 1270 1284 log_it("edit_raidlist_entry - calling"); … … 1350 1364 } 1351 1365 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); 1356 1368 strcpy(raidlist->disks.el[raidlist->disks.entries++].device, temp); 1357 1369 } … … 1426 1438 void *keylist[10]; 1427 1439 void *curr_choice; 1440 char *raidlevel = NULL; 1441 char *chunksize = NULL; 1442 char *msg = NULL; 1428 1443 1429 1444 int currline2 = 0; 1445 int res = 0; 1430 1446 1431 1447 log_it("Started edit_raidlist_entry"); … … 1457 1473 keylist[i] = (void *) i; 1458 1474 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]; 1461 1476 switch (raidrec->plex[i].raidlevel) { 1462 1477 case -1: 1463 strcpy(raidlevel, "concat");1478 mr_asprintf(&raidlevel, "concat"); 1464 1479 break; 1465 1480 case 0: 1466 strcpy(raidlevel, "striped");1481 mr_asprintf(&raidlevel, "striped"); 1467 1482 break; 1468 1483 case 5: 1469 strcpy(raidlevel, "raid5");1484 mr_asprintf(&raidlevel, "raid5"); 1470 1485 break; 1471 1486 default: 1472 sprintf(raidlevel, "raid%i", 1473 raidrec->plex[i].raidlevel); 1487 mr_asprintf(&raidlevel, "raid%i", raidrec->plex[i].raidlevel); 1474 1488 break; 1475 1489 } 1476 1490 1477 1491 if (raidrec->plex[i].raidlevel == -1) { 1478 strcpy(chunksize, "N/A");1492 mr_asprintf(&chunksize, "N/A"); 1479 1493 } else { 1480 sprintf(chunksize, "%dk", raidrec->plex[i].stripesize);1494 mr_asprintf(&chunksize, "%dk", raidrec->plex[i].stripesize); 1481 1495 } 1482 1496 snprintf(pname, 64, "%s.p%i", raidrec->volname, i); … … 1484 1498 pname, raidlevel, chunksize, 1485 1499 raidrec->plex[i].subdisks); 1500 mr_free(raidlevel); 1501 mr_free(chunksize); 1502 1486 1503 newtListboxAppendEntry(plexesListbox, entry, keylist[i]); 1487 1504 } … … 1505 1522 1506 1523 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) { 1511 1529 log_it("Deleting RAID plex"); 1512 1530 memcpy((void *) &raidrec->plex[currline2], … … 1850 1868 } 1851 1869 } 1852 #if 01853 } else {1854 edit_raid_subdisk(raidlist, raidrec, &raidrec->sd[currline3],1855 currline3);1856 }1857 #endif1858 1870 newtFormDestroy(editraidForm); 1859 1871 newtRefresh(); … … 1894 1906 } 1895 1907 } 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 */1899 1908 1900 1909 #endif … … 1937 1946 1938 1947 /** buffers **********************************************************/ 1939 char tmp[MAX_STR_LEN];1948 char *tmp = NULL; 1940 1949 char *flaws_str_A = NULL; 1941 1950 char *flaws_str_B = NULL; … … 1961 1970 bCancel = newtCompactButton(i += 12, 17, "Cancel"); 1962 1971 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)"); 1965 1973 headerMsg = newtLabel(2, 1, tmp); 1966 1974 flawsLabelA = newtLabel(2, 13, flaws_str_A); … … 1997 2005 } else if (b_res == bReload) { 1998 2006 if (ask_me_yes_or_no("Reload original mountlist?")) { 1999 /*2000 This would be really dumb. RAIDTAB_FNAME is #define'd. --- Hugo, 2003/04/242001 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 */2007 2007 load_mountlist(mountlist, mountlist_fname); 2008 2008 load_raidtab_into_raidlist(raidlist, RAIDTAB_FNAME); … … 2038 2038 } 2039 2039 } 2040 paranoid_free(flaws_str_A);2041 paranoid_free(flaws_str_B);2042 paranoid_free(flaws_str_C);2043 2040 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 2044 2047 newtPopWindow(); 2045 2048 newtPopHelpLine(); … … 2221 2224 int i = 0; 2222 2225 #ifdef __FreeBSD__ 2223 char vdev[64]; 2226 char *vdev = NULL; 2227 int res = 0; 2224 2228 #else 2225 2229 // Linux … … 2231 2235 #ifdef __FreeBSD__ 2232 2236 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) 2235 2242 break; 2236 2243 } … … 2595 2602 { 2596 2603 /** buffers ********************************************************/ 2597 char tmp[MAX_STR_LEN];2604 char *tmp = NULL; 2598 2605 2599 2606 /** int ************************************************************/ … … 2607 2614 pos = which_raid_device_is_using_this_partition(raidlist, old_dev); 2608 2615 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); 2611 2617 log_it(tmp); 2618 mr_free(tmp); 2612 2619 } else { 2613 2620 if ((j = … … 2641 2648 #endif 2642 2649 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); 2646 2651 log_it(tmp); 2652 mr_free(tmp); 2647 2653 } 2648 2654 } -
branches/2.2.10/tools/quality
r2296 r2300 28 28 29 29 # 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 ; do30 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 mr_system assert; do 31 31 echo "monodrescue $s usage : " 32 32 tot=0
Note:
See TracChangeset
for help on using the changeset viewer.